#include<iostream>
#include<cstdio>
#include<cmath>
#include<stack>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    stack<int> s;
    int cnt=1,cnt2=1;
    int ans=0;
    for(int i=0;i<(n<<1);i++)
    {
        char c[10];
        scanf("%s",c);
        if(c[0]=='a')
        {
            int temp;
            scanf("%d",&temp);
            s.push(temp);
        }
        else
        {
            if(s.size()==0)
            {
                continue;
            }
            else if(s.top()==cnt)
            {
                cnt++;
                cnt2++;
                s.pop();
            }
            else
            {
                ans++;
                cnt=s.top()+1;
                while(s.size())
                    s.pop();
            }
        }
    }
    printf("%d\n",ans);
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<ctime>

#define scan(n) scanf("%d",&n)

using namespace std;

int a[300005];
vector<int> s;

int main()
{
    int n,i,j,num=0,k=1;
    int sum=0;
    string ss;
    cin>>n;
    for(int j=1;j<=2*n;j++)
    {
        cin>>ss;
        if(ss=="add")
        {
            scan(num);
            s.push_back(num);
        }
        else
        {
            if(s.back()==k)
            {
                k++;
                s.pop_back();
            }
            else if(s.empty())
            {
                k++;
            }
            else
            {
                sum++;
                s.clear();
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

stack<int> stk;
int main()
{
    int n, ind = 1, res = 0, now = 1;
    scanf("%d", &n);
    for(int i = 0; i < 2*n; i++)
    {
        string s;
        int x;
        cin >> s;
        if(s == "add")
        {
            scanf("%d", &x);
            stk.push(x);
        }
        else
        {
            if(stk.empty())
            {
                continue;
            }
            else if(stk.top() != ind)
            {
                res++;
                while(!stk.empty()) stk.pop();
            }
            else
            {
                stk.pop();
            }
        }
    }
    printf("%d", res);
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<ctime>

#define scan(n) scanf("%d",&n)

using namespace std;

int a[300005];
vector<int> s;

int main()
{
    int n,i,j,num=0,k=1;
    int sum=0;
    string ss;
    cin>>n;
    for(int j=1;j<=2*n;j++)
    {
        cin>>ss;
        if(ss=="add")
        {
            scan(num);
            s.push_back(num);
        }
        else
        {
            if(s.back()==k)
            {
                k++;
                s.pop_back();
            }
            else if(s.empty())
            {
                k++;
            }
            else
            {
                sum++;
                k++;
                s.clear();
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<cstdio>
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define maxn 800008
using namespace std;
vector<int>st;
int main(){
//    cout<<(3^1+4^2+5^3+6^4+5^5);
    int n;

    scanf("%d",&n);
    int cnt=1;
    int ans=0;

    rep(i,0,2*n){
        char s[100];
        int x;
        scanf("%s",s);
        if(s[0]=='a')
        {
            scanf("%d",&x);
            st.push_back(x);
        }
        else{
            if(st.empty());
            else if(st.back()==cnt)
                st.pop_back();
            else{
                ans++;
                st.clear();
            }
            cnt++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<stack>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    stack<int> s;
    int cnt=1;
    int ans=0;
    for(int i=0;i<(n<<1);i++)
    {
        char c[10];
        scanf("%s",c);
        if(c[0]=='a')
        {
            int temp;
            scanf("%d",&temp);
            s.push(temp);
        }
        else
        {
            if(s.size()==0)
                cnt++;
            else if(s.top()==cnt)
            {
                cnt++;
                s.pop();
            }
            else
            {
                ans++;
                cnt++;
                while(s.size())
                    s.pop();
            }
        }
    }
    printf("%d\n",ans);
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<stack>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    stack<int> s;
    int cnt=1;
    int ans=0;
    for(int i=0;i<(n<<1);i++)
    {
        char c[10];
        scanf("%s",c);
        if(c[0]=='a')
        {
            int temp;
            scanf("%d",&temp);
            s.push(temp);
        }
        else
        {
            if(s.size()==0)
                continue;
            else if(s.top()==cnt)
            {
                cnt++;
                s.pop();
            }
            else
            {
                ans++;
                cnt++;
                while(s.size())
                    s.pop();
            }
        }
    }
    printf("%d\n",ans);
}


//Okabe and Boxes
#include <iostream>
#include <stack>
using namespace std;
int main()
{
    stack<int> s;
    int num=1;
    int ans = 0;
    int n;
    cin>>n;
    char str[100];
    for (int i = 0; i < 2 * n;i++)
    {
        cin>>str;
        if(str[0]=='a')
        {
            int x;
            cin>>x;
            s.push(x);
        }
        else
        {
            if(s.empty()) continue;
            if(s.top()==num)
            {
                s.pop();
                num++;
            }
            else
            {
                while(!s.empty()) s.pop();
                ans++;
                num++;
            }
        }
    }
    cout << ans << endl;
}


#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stack>
using namespace std;
typedef long long int ll;
char str[10];
vector<int>p;
int n,x,cnt,ans,d;
int main()
{
    scanf("%d",&n);
     cnt=1;
     ans=0;
    for(int i=1;i<=2*n;i++)
    {
       scanf("%s",str);
        if(str[0]=='a')
        {
            scanf("%d",&x);
            p.push_back(x);
        }
        else
        {
            if(p.empty());
            else if(p.back()==cnt) p.pop_back();
            else ans++,p.clear();
            cnt++;
        }
    }
    cout<<ans<<endl;
}


// Okabe and Boxes
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int num[300010];

int main()
{
    int rsp = 0;
    int top = 1;
    int ans = 0;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < 2 * n; i++)
    {
        char a[10];
        scanf("%s", a);
        if (a[0] == 'a')
        {
            scanf("%d", &num[rsp++]);
        }
        else
        {
            if (rsp == 0)
                ;
            else
            {
                if (num[rsp - 1] == top)
                    rsp--;
                else
                {
                    rsp = 0;
                    ans++;
                }
            }
            top++;
        }
    }
    printf("%d\n", ans);

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> a;
int mian()
{
	int n;
	cin>>n;
	int c;
	int tmp=1;
	int time=0;
	char b[10];
	for(int i=0;i<2*n;i++)
	{
		cin>>b;
		if(b[0]=='a')
		{
			cin>>c;
			a.push_back(c);
		}
		else
		{
			if(a[a.size()-1]==tmp)
			{
				a.pop_back();
				tmp++;
			}
			else
			{
				time++;
				int m=a.find(a.begin(),a.end(),tmp);
				a.erase(m);
				tmp++;
			}
		}
	}
	cout<<time;
 }


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <climits>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <ctime>
#include <ctype.h>

#define INF 0x3f3f3f3f
#define EXP 1e-8
#define MEM(a,x) memset(a,x,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define LL long long
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _fore(i,a,b) for(int i = (a); i <= (b); i++)
const double PI = acos(-1.0);

using namespace std;

char str[10];
vector<int> vec;

int main() {
    int n, cnt = 1, ans = 0;
    cin >> n;
    for(int i = 1; i <= 2 * n; i++) {
        cin >> str;
        if(str[0] == 'a') {
            int temp;
            cin >> temp;
            vec.push_back(temp);
        } else {
            if(vec.empty());
            else if(vec.back() == cnt)
                vec.pop_back();
            else
                ans++, vec.clear();
            cnt++;
        }
    }
    cout << ans << endl;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<ctime>

#define scan(n) scanf("%d",&n)

using namespace std;

int a[300005];
stack<int> s;

int main()
{
    int n,i,j,num=0,k=1;
    int sum=0;
    string ss;
    cin>>n;
    for(int j=1;j<=2*n;j++)
    {
        cin>>ss;
        if(ss=="add")
        {
            scan(num);
            s.push(num);
        }
        else
        {
            if(s.top()==k)
            {
                k++;
                s.pop();
            }
            else if(s.top()==-1)
            {
                k++;
            }
            else
            {
                sum++;
                s.push(-1);
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
//sjc
using namespace std;
typedef long long ll;
stack<int>s;
char oper[1005];
int main()
{
	int n,op=0,k=0;
	scanf("%d", &n);
	for (int i = 1; i <= 2 * n; i++)
	{
		int temp=-1;
		scanf("%s", oper);
		if (oper[0] == 'a')
		{
			scanf("%d", &temp);
			s.push(temp);
		}
		else
		{
			k++;
			if (s.empty());
			else if (s.top() != k)
			{
				op++;
				while (!s.empty())s.pop();
			}
			else s.pop();
		}
	}
	printf("%d\n", op);
	return 0;
}


// Okabe and Boxes
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int num[300010];

int main()
{
    int rsp = 0;
    int top = 1;
    int ans = 0;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < 2 * n; i++)
    {
        char a[10];
        scanf("%s", a);
        if (a[0] == 'a')
        {
            scanf("%d", &num[rsp++]);
        }
        else
        {
            if (rsp == 0)
                ;
            else
            {
                if (num[rsp - 1] == top)
                    rsp--;
                else
                {
                    rsp = 0;
                    ans++;
                }
                top++;
            }
        }
    }
    printf("%d\n", ans);

    return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;

//ifstream fin("input.txt");
//ofstream fout("output.txt");

int main() {
	stack<int> boxes;
	string s;
	int n, k, rem = 1, res = 0;
	cin >> n;
	n <<= 1;
	for (size_t i = 0; i < n; i++)
	{
		cin >> s;
		if (s == "add") {
			cin >> k;
			boxes.push(k);
		}
		else {
			if (!boxes.empty()) {
				if (boxes.top() != rem) {
					res++;
					boxes = stack<int>();
				}
				else
				{
					boxes.pop();
				}
			}
			rem++;
		}
	}
	cout << res;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

//ifstream fin("input.txt");
//ofstream fout("output.txt");

int main() {
	vector<int> boxes;
	string s;
	int n, k, rem = 1, res = 0;
	cin >> n;
	n <<= 1;
	for (size_t i = 0; i < n; i++)
	{
		cin >> s;
		if (s == "add") {
			cin >> k;
			boxes.emplace_back(k);
		}
		else {
			if (boxes.back() != rem) {
				res++;
				sort(boxes.begin(), boxes.end(), greater<int>());
			}
			boxes.pop_back();
			rem++;
		}
	}
	cout << res;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

int main() {
	stack<int> boxes;
	string s;
	int n, k, rem = 1, res = 0;
	fin >> n;
	n <<= 1;
	for (size_t i = 0; i < n; i++)
	{
		fin >> s;
		if (s == "add") {
			fin >> k;
			boxes.push(k);
		}
		else {
			if (!boxes.empty()) {
				if (boxes.top() != rem) {
					res++;
					boxes = stack<int>();
				}
				else
				{
					boxes.pop();
				}
			}
			rem++;
		}
	}
	cout << res;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;

//ifstream fin("input.txt");
//ofstream fout("output.txt");

int main() {
	vector<int> boxes;
	string s;
	int n, k, rem = 1, res = 0;
	cin >> n;
	n <<= 1;
	for (size_t i = 0; i < n; i++)
	{
		cin >> s;
		if (s == "add") {
			cin >> k;
			boxes.emplace_back(k);
		}
		else {
			if (boxes.back() != rem) {
				res++;
				sort(boxes.begin(), boxes.end(), greater<int>());
			}
			boxes.pop_back();
			rem++;
		}
	}
	cout << res;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

int main() {
	vector<int> boxes;
	string s;
	int n, k, rem = 1, res = 0;
	fin >> n;
	n <<= 1;
	for (size_t i = 0; i < n; i++)
	{
		fin >> s;
		if (s == "add") {
			fin >> k;
			boxes.emplace_back(k);
		}
		else {
			if (boxes.back() != rem) {
				res++;
				sort(boxes.begin(), boxes.end(), greater<int>());
			}
			boxes.pop_back();
			rem++;
		}
	}
	fout << res;
}


#include<iostream>
#include<queue>
#include<cstdio>
#include<string>

using namespace std ;

int main()
{
	priority_queue <int, vector<int>, greater<int> > stk ;
	int n , m , x ;
	int num = 0 ;
	string str ;
	scanf("%d",&n) ;
	m = 2*n ;
	while(m--)
	{
		cin >> str ;
		if ( str == "add")
		{

			scanf("%d",&x) ;

			if (stk.empty())
				stk.push(x) ;
			else if ( x > stk.top() )
			{
				num++ ;
				stk.push(x) ;
			}
			else
				stk.push(x) ;
		}
		else
			stk.pop() ;
	}
	cout << num ;
	return 0 ;
}


#include<iostream>
#include<cstdio>
#include<string>

using namespace std ;

int a[300005] ;

int main()
{
	string str ;
	int n , m , x, i  ;
	int num = 0 ;
	int sum = 0 ;
	int k = 1 ;
	cin >> n ;
	m = 2*n ;
	while(m--)
	{
		cin >> str ;
		if ( str == "add")
		{
			cin >> x ;
			a[++num] = x ;
		}
		else
		{
			if ( num > 0 && a[num] != k )
				sum++ , num = 0 ;
			else if ( num > 0 )
				num-- ;
			k++ ;
		}
	}
	cout << sum ;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<functional>
#include<algorithm>
#include<ctype.h>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<map>
#include<list>
#include<set>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define PI acos(-1)
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXn = 3e5 + 15;
stack <int >a;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n,k,cnt=1,num=1,p=0,sum=0,max1=0,ok=0;
    char s[20];
    scanf("%d ",&n);
    for(int i=1; i<=2*n; i++)
    {
        scanf(" %s",s);
        if(strcmp(s,"add")==0)
        {
            scanf("%d",&k);
            a.push(k);
        }
        else
        {
            if(!a.empty())
            {
                k=a.top();
                if(k==num)
                {
                    a.pop();
                }
                else if(!a.empty())
                {
                    sum++;
                    while(!a.empty())
                    {
                        a.pop();
                    }
                }
            }
            num++;
        }
    }
    printf("%d\n",sum);
    return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<functional>
#include<algorithm>
#include<ctype.h>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<map>
#include<list>
#include<set>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define PI acos(-1)
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXn = 3e5 + 15;
list <int >a;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n,k,cnt=1,num=1,sum=0,max1=0,ok=0;
    char s[20];
    scanf("%d ",&n);
    for(int i=1;i<=2*n;i++)
    {
        scanf(" %s",s);
        if(strcmp(s,"add")==0)
        {
            scanf("%d",&k);
            a.push_back(k);
            if(max1<k)
                max1=k,ok=0;
        }
        else
        {
            if(k==num||(num<=max1&&ok==1)){
                a.remove(num);
                k=a.back();
            }
            else if(k!=num)
            {
                sum++;
                k=num+1;
                ok=1;
            }
            num++;
        }
    }
    printf("%d\n",sum);
    return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<functional>
#include<algorithm>
#include<ctype.h>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<map>
#include<list>
#include<set>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define PI acos(-1)
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXn = 3e5 + 15;
stack <int >a;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n,k,cnt=1,num=1,p=0,sum=0,max1=0,ok=0;
    char s[20];
    scanf("%d ",&n);
    for(int i=1; i<=2*n; i++)
    {
        scanf(" %s",s);
        if(strcmp(s,"add")==0)
        {
            scanf("%d",&k);
            a.push(k);
        }
        else
        {
            if(!a.empty())
            {
                k=a.top();
                if(k==num)
                {
                    a.pop();
                    num++;
                }
                else if(!a.empty())
                {
                    sum++;
                    while(!a.empty())
                    {
                        a.pop();
                        num++;
                    }
                }
            }
        }
    }
    printf("%d\n",sum);
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<vector>
#include<iomanip>
#define ll long long
#define stop system("pause")
#define pb push_back
#define cint(n) int n; cin >> n
#define cill(n) ll n; cin >> n;
#define print(n) ll n; cout << n;
#define veci vector <int>;
#pragma warning(disable:4996)
using namespace std;

vector <int> cl(vector <int> A) {
	for (int i = 0; i < A.size();  i++) {
		A[i] = 0;
	}
	return A;
}
/*vector<int>dAns(100001);
vector<vector<int>>arr(100001);

void dfs(int v, int d)
{
for (int i = 0; i < arr[v].size(); i++)
{
dAns[d + 1]++;
dfs(arr[v][i], d + 1);
}
}

int bfs(vector<vector<int>>v, ll n, ll m) {
vector<int>hg(n);
hg[0] = 1;
queue<int>qq;
qq.push(0);
while (qq.size() != 0) {
for (int i = 0; i < v[qq.front()].size(); i++) {
if (hg[v[qq.front()][i]] == 0) {
qq.push(v[qq.front()][i]);
hg[v[qq.front()][i]] = 1 + hg[qq.front()];
}

}
qq.pop();

}
return(hg[n - 1]);
}
*/
int qweq(int x)
{
	ll cc = 0;
	while (x > 0) {
		cc += x % 10;
		x /= 10;
	}
	return(cc);

}

int main()
{
	//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	ll q=999999999, n, w, e, r = 0, k, ww, m, qq = 0;
	string s = "";
	deque<ll>dd;
	cin >> n;
	ll ans = 0;
	qq = 1;
	for (int i = 0; i < n * 2; i++) {
		cin >> s;
		if (s[0] == 'a'){
			cin >> q;
			dd.pb(q);
			qq--;
		}
		else if (dd.size() == 0) {
			k = 1;
		}
		else if (dd.back() == qq)
			dd.pop_back();
		else {
			dd.clear();
			ans++;
		}
		qq++;
	}
	cout << ans;
	q = 1;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<vector>
#include<iomanip>
#define ll long long
#define stop system("pause")
#define pb push_back
#define cint(n) int n; cin >> n
#define cill(n) ll n; cin >> n;
#define print(n) ll n; cout << n;
#define veci vector <int>;
#pragma warning(disable:4996)
using namespace std;

vector <int> cl(vector <int> A) {
	for (int i = 0; i < A.size();  i++) {
		A[i] = 0;
	}
	return A;
}
/*vector<int>dAns(100001);
vector<vector<int>>arr(100001);

void dfs(int v, int d)
{
for (int i = 0; i < arr[v].size(); i++)
{
dAns[d + 1]++;
dfs(arr[v][i], d + 1);
}
}

int bfs(vector<vector<int>>v, ll n, ll m) {
vector<int>hg(n);
hg[0] = 1;
queue<int>qq;
qq.push(0);
while (qq.size() != 0) {
for (int i = 0; i < v[qq.front()].size(); i++) {
if (hg[v[qq.front()][i]] == 0) {
qq.push(v[qq.front()][i]);
hg[v[qq.front()][i]] = 1 + hg[qq.front()];
}

}
qq.pop();

}
return(hg[n - 1]);
}
*/
int qweq(int x)
{
	ll cc = 0;
	while (x > 0) {
		cc += x % 10;
		x /= 10;
	}
	return(cc);

}

int main()
{
	//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	ll q=999999999, n, w, e, r = 0, k, ww, m, qq = 0;
	string s = "";
	deque<ll>dd;
	cin >> n;
	ll ans = 0;
	qq = 1;
	for (int i = 0; i < n * 2; i++) {
		cin >> s;
		if (s[0] == 'a'){
			cin >> q;
			dd.pb(q);
			qq--;
		}
		else if (dd.size() == 0) {
			k = 1;
		}
		else if (dd.back() == qq)
			dd.pop_back();
		else {
			dd.clear();
			ans++;
		}
	}
	cout << ans-1;
	q = 1;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
using namespace std;
int n, ans;
string s;
vector<int> vec;
bool Comp(const int &a, const int &b)
{
	return a > b;
}
int main()
{
	cin >> n;
	ans = 0;
	int num;
	int judge = 1;
	for (int i = 1;i <= 2 * n;i++)
	{
		cin >> s;
		if (s == "add")
		{
			cin >> num;
			vec.push_back(num);
			judge = 0;
		}
		if (s == "remove")
		{
			if (judge == 0)
			{
				for (int j = vec.size() - 1;j > 0;j--)
				{
					if (vec[j] > vec[j - 1])
					{
						sort(vec.begin(), vec.end(), Comp);
						ans++;
						judge = 1;
					}
				}
			}
			vec.pop_back();
		}
	}
	cout << ans;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
using namespace std;
int n, ans;
string s;
vector<int> vec;
bool comp(const int &a, const int &b)
{
	return a > b;
}
int main()
{
	cin >> n;
	ans = 0;
	int num;
	int pp = 1;//弹出到的数字
	for (int i = 1;i <= 2 * n;i++)
	{
		cin >> s;
		if (s == "add")
		{
			cin >> num;
			vec.push_back(num);
		}
		if (s == "remove")
		{
			if (vec.empty());
			else if (vec.back() == pp)
				vec.pop_back();
			else
			{
				vec.clear();
				ans++;
			}
			pp++;
		}
	}
	cout << ans;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
using namespace std;
int n, ans;
string s;
vector<int> vec;
bool comp(const int &a, const int &b)
{
	return a > b;
}
int main()
{
	cin >> n;
	ans = 0;
	int num;
	int judge = 1;
	for (int i = 1;i <= 2 * n;i++)
	{
		cin >> s;
		if (s == "add")
		{
			cin >> num;
			vec.push_back(num);
			judge = 0;
		}
		if (s == "remove")
		{
			if (judge == 0)
			{
				for (int j = vec.size() - 1;j > 0;j--)
				{
					if (vec[j] > vec[j - 1])
					{
						sort(vec.begin(), vec.end(), comp);
						ans++;
						judge = 1;
					}
				}
			}
			vec.pop_back();
		}
	}
	cout << ans;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
using namespace std;
int n, ans;
string s;
vector<int> vec;
bool comp(const int &a, const int &b)
{
	return a > b;
}
int main()
{
	cin >> n;
	ans = 0;
	int num;
	int pp = 1;//弹出到的数字
	for (int i = 1;i <= 2 * n;i++)
	{
		cin >> s;
		if (s == "add")
		{
			cin >> num;
			vec.push_back(num);
		}
		if (s == "remove")
		{
			if (vec.back() == pp);
			else
			{
				sort(vec.begin(), vec.end(), comp);
				ans++;
			}
			vec.pop_back();
			pp++;
		}
	}
	cout << ans;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
using namespace std;
int n, ans;
string s;
vector<int> vec;
bool Comp(const int &a, const int &b)
{
	return a > b;
}
int main()
{
	cin >> n;
	ans = 0;
	int num;
	for (int i = 1;i <= 2 * n;i++)
	{
		cin >> s;
		if (s == "add")
		{
			cin >> num;
			vec.push_back(num);
		}
		if (s == "remove")
		{
			for (int j = vec.size() - 1;j > 0;j--)
			{
				if (vec[j] > vec[j - 1])
				{
					sort(vec.begin(), vec.end(), Comp);
					ans++;
				}
			}
			vec.pop_back();
		}
	}
	cout << ans;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
using namespace std;
int n, ans;
string s;
vector<int> vec;
bool Comp(const int &a, const int &b)
{
	return a > b;
}
int main()
{
	cin >> n;
	ans = 0;
	int num;
	for (int i = 1;i <= 2 * n;i++)
	{
		cin >> s;
		if (s == "add")
		{
			cin >> num;
			vec.push_back(num);
		}
		if (s == "remove")
		{
			for (int j = vec.size() - 1;j > 0;j--)
			{
				if (vec[j] > vec[j - 1])
				{
					sort(vec.begin(), vec.end(), Comp);
					ans++;
				}
			}
		}
	}
	cout << ans;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<functional>
#include<algorithm>
#include<ctype.h>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<map>
#include<list>
#include<set>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define PI acos(-1)
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXn = 3e5 + 15;
list <int >a;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n,k,cnt=1,num=1,p=0,sum=0,max1=0,ok=0;
    char s[20];
    scanf("%d ",&n);
    for(int i=1;i<=2*n;i++)
    {
        scanf(" %s",s);
        if(strcmp(s,"add")==0)
        {
            scanf("%d",&k);
            a.push_back(k);
            if(max1<k)
                max1=k;
        }
        else
        {
            if(k==num||num<=p){
                a.remove(num);
                k=a.back();
            }
            else if(k!=num)
            {
                sum++;
                k=num+1;
                p=max1;
            }
            num++;
        }
    }
    printf("%d\n",sum);
    return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<functional>
#include<algorithm>
#include<ctype.h>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<map>
#include<list>
#include<set>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define PI acos(-1)
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXn = 3e5 + 15;
list <int >a;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n,k,cnt=1,num=1,sum=0,max1=0,ok=0;
    char s[20];
    scanf("%d ",&n);
    for(int i=1;i<=2*n;i++)
    {
        scanf(" %s",s);
        if(strcmp(s,"add")==0)
        {
            scanf("%d",&k);
            a.push_back(k);
            if(max1<k)
                max1=k,ok=0;
        }
        else
        {
            if(k==num||(num<=max1&&ok==1)){
                a.remove(num);
            }
            else if(k!=num)
            {
                sum++;
                k=num+1;
                ok=1;
            }
            num++;
        }
    }
    printf("%d\n",sum);
    return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stack>
using namespace std;
const int max_n = 3e5 + 100;
int n;
string com;
stack<int> st;
int cmp = 1;

int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	int ans = 0;
	for (int i = 1;i <= n << 1;++i) {
		cin >> com;
		if (com == "remove") {
			if (st.empty() || st.top() == cmp) {
				++cmp;
				if (!st.empty())st.pop();
			}
			else {
				while (!st.empty())st.pop();
				++cmp;++ans;
			}
		}
		else {
			int val;cin >> val;
			st.push(val);
		}
	}cout << ans << endl;
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int max_n = 3e5 + 100;
int n;
string com;

int st[max_n];
int up = 0;
int cmp = 1;
bool check() {
	if (up == 0 || st[up - 1] == cmp) {
		++cmp;
		return true;
	}return false;
}
void push(int val) {
	st[up++] = val;
}
bool remove() {
	if (up == 0)return false;
	--up;return true;
}

int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	int ans = 0;
	for (int i = 1;i <= n << 1;++i) {
		cin >> com;
		if (com == "remove") {
			if (check())remove();
			else {
				++ans;
				while (remove());
			}
		}
		else {
			int val;cin >> val;
			push(val);
		}
	}cout << ans << endl;
}


#include <stack>
#include <cstdio>
#include <cstring>
using namespace std;
char s[10];
int main()
{
	int n, num;
	stack<int> boxes;
	scanf("%d", &n);
	int count = 0;
	int min_box = 1;
	int flag = 0;
	for (int i = 0; i < 2 * n; i++)
	{
		scanf("%s", s);
		if (strcmp(s, "add") == 0)
		{
			flag = 0;
			scanf("%d", &num);
			boxes.push(num);
		}
		else if (strcmp(s, "remove") == 0)
		{
			if (flag == 0 && min_box != boxes.top())
			{
				while (boxes.top() < min_box)
					boxes.pop();
				if (boxes.top() == min_box)
				{
					min_box++;
					boxes.pop();
				}
				else
				{
					flag = 1;
					count++;
					min_box++;
				}
			}
			else if (flag == 0 && boxes.top() == min_box)
			{
				min_box++;
				boxes.pop();
			}
			else if (flag == 1)
				min_box++;
		}

	}
	printf("%d", count);
}


#include <stack>
#include <cstdio>
#include <cstring>
using namespace std;
char s[10];
int main()
{
	int n, num;
	stack<int> boxes;
	scanf("%d", &n);
	int count = 0;
	int min_box = 1;
	int flag = 0;
	for (int i = 0; i < 2 * n; i++)
	{
		scanf("%s", s);
		if (strcmp(s, "add") == 0)
		{
			flag = 0;
			scanf("%d", &num);
			boxes.push(num);
		}
		else if (strcmp(s, "remove") == 0)
		{
			if (flag == 0 && min_box != boxes.top())
			{
				flag = 1;
				count++;
				min_box++;

			}
			else if (boxes.top() == min_box)
			{
				min_box++;
				boxes.pop();
			}
			else if (flag == 1)
				min_box++;
		}

	}
	printf("%d", count);
}


#include <stack>
#include <cstdio>
#include <cstring>
using namespace std;
char s[10];
int main()
{
	int n, num;
	stack<int> boxes;
	scanf("%d", &n);
	int count = 0;
	int min_box = 1;
	int flag = 0;
	for (int i = 0; i < 2 * n; i++)
	{
		scanf("%s", s);
		if (strcmp(s, "add") == 0)
		{
			flag = 0;
			scanf("%d", &num);
			boxes.push(num);
		}
		else if (strcmp(s, "remove") == 0)
		{
			if (flag == 0 && min_box != boxes.top())
			{
				flag = 1;
				count++;
				min_box++;

			}
			else if (flag == 0 && boxes.top() == min_box)
			{
				min_box++;
				boxes.pop();
			}
			else if (flag == 1)
				min_box++;
		}

	}
	printf("%d", count);
}


#include <stack>
#include <cstdio>
#include <cstring>
using namespace std;
char s[10];
int main()
{
	int n, num;
	stack<int> boxes;
	scanf("%d", &n);
	int count = 0;
	int min_box = 1;
	int flag = 0;
	for (int i = 0; i < 2 * n; i++)
	{
		scanf("%s", s);
		if (strcmp(s, "add") == 0)
		{
			flag = 0;
			scanf("%d", &num);
			boxes.push(num);
		}
		else if (strcmp(s, "remove") == 0)
		{
			if (flag == 0 && min_box != boxes.top())
			{
				while (boxes.top() < min_box)
					boxes.pop();
				if (boxes.top() == min_box)
				{
					flag = 1;
					min_box++;
					boxes.pop();
				}
				else
				{
					flag = 1;
					count++;
					min_box++;
				}
			}
			else if (flag == 0 && boxes.top() == min_box)
			{
				min_box++;
				boxes.pop();
			}
			else if (flag == 1)
				min_box++;
		}

	}
	printf("%d", count);
}


#include <stack>
#include <cstdio>
#include <cstring>
using namespace std;
char s[10];
int main()
{
	int n, num;
	stack<int> boxes;
	stack<int> poses;
	scanf("%d", &n);
	int count = 0;
	int min_box = 1;
	int flag = 0;
	int pos = -1;
	for (int i = 0; i < 2 * n; i++)
	{
		scanf("%s", s);
		if (strcmp(s, "add") == 0)
		{
			flag = 0;
			scanf("%d", &num);
			boxes.push(num);
			poses.push(i);
		}
		else if (strcmp(s, "remove") == 0)
		{
			if (flag == 0 && min_box != boxes.top())
			{
				while (boxes.top() < min_box)
				{
					boxes.pop();
					poses.pop();
				}

				if (boxes.top() == min_box)
				{
					flag = 1;
					min_box++;
					boxes.pop();
					poses.pop();
				}
				else
				{
					if (poses.top() <= pos)
					{
						flag = 1;
						min_box++;
					}
					else
					{
						flag = 1;
						min_box++;
						count++;
						pos = i - 1;
					}
				}
			}
			else if (flag == 0 && boxes.top() == min_box)
			{
				min_box++;
				boxes.pop();
				poses.pop();
			}
			else if (flag == 1)
				min_box++;
		}

	}
	printf("%d", count);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional>

#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))

using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 1e6+100;
const int maxm = 2e6+100;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);

char a[maxn];
vector<int>v;
bool cmp(int a, int b){
    return a>b;
}
int main(){
    int n;
    scanf("%d", &n);
    int p = 1;
    int top;
    int ans = 0;
    for(int i = 1; i <= 2*n; i++){
        scanf("%s",a+1);
        if(a[1]=='a'){
            int x;
            scanf("%d", &x);
            v.pb(x);
        }
        else if(a[1]=='r'){
            if(v.back()!=p){
                ans++;
                sort(v.begin(), v.end(), cmp);
            }
            p++;
            v.pop_back();
        }
    }
    printf("%d",ans);
    return 0;
}
/*

 */


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define MAXN 300005
#define ll long long
using namespace std;
ll n,m,num,z,cnt,aw,ans;
ll a[MAXN];
string s;

int main()
{
    cin>>n;
    for(ll i=1;i<=2*n;i++)
    {
    	cin>>s;
    	if(s[0]=='a') scanf("%lld",&a[++cnt]);
    	else
    	{
    		z++;
    		if(a[cnt]!=z&&cnt>num)
    		{
    			ans++;
    			num=cnt-1;
    		}
			cnt--;
    		num=min(num,cnt);
    	}//234546
    }//123456
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

stack<int> stk;
int main()
{
    int n, ind = 0, res = 0, now = 1;
    scanf("%d", &n);
    for(int i = 0; i < 2*n; i++)
    {
        string s;
        int x;
        cin >> s;
        if(s == "add")
        {
            scanf("%d", &x);
            stk.push(x);
        }
        else
        {
            ind++;
            if(stk.empty())
            {
                continue;
            }
            else if(stk.top() != ind)
            {
                res++;
                while(!stk.empty()) stk.pop();
            }
            else
            {
                stk.pop();
            }
        }
    }
    printf("%d", res);
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <climits>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <ctime>
#include <ctype.h>

#define INF 0x3f3f3f3f
#define EXP 1e-8
#define MEM(a,x) memset(a,x,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define LL long long
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _fore(i,a,b) for(int i = (a); i <= (b); i++)
const double PI = acos(-1.0);

using namespace std;
inline void inQueue(deque<int>& dq, int num) {
    while(!dq.empty() && dq.back() < num)
        dq.pop_back();
    dq.push_back(num);
}

inline void outQueue(deque<int>& dq, int num) {
    if (dq.front() == num)
        dq.pop_front();
}

inline void inQueue2(deque<int>& dq, int num) {
    while(!dq.empty() && dq.back() > num)
        dq.pop_back();
    dq.push_back(num);
}

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int *arr = new int[n + 5];
    deque<int> maxx, minn;    //maxx递减，minn递增
    int *ans1 = new int[n + 5];
    int *ans2 = new int[n + 5];
    int index1 = 0, index2 = 0;
    _fore (i, 1, n) {
        cin >> arr[i];
        inQueue(maxx, arr[i]);
        inQueue2(minn, arr[i]);
        if (i >= k) {
            ans1[index1++] = maxx.front();
            outQueue(maxx, arr[i - k + 1]);
            ans2[index2++] = minn.front();
            outQueue(minn, arr[i - k + 1]);
        }
    }
    _for (i, 0, n - k + 1) {
        cout << ans2[i] << (i == n - k ? '\n' : ' ');
    }
    _for (i, 0, n - k + 1) {
        cout << ans1[i] << (i == n - k ? '\n' : ' ');
    }
    delete []arr;
    delete []ans1;
    delete []ans2;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define MAXN 300005
#define ll long long
using namespace std;
ll n,m,t,num,z,cnt,aw,ans;
ll a[MAXN];
string s;

int main()
{
    cin>>n;
    for(ll i=1;i<=2*n;i++)
    {
    	cin>>s;
    	if(s[0]=='a') scanf("%lld",&a[++cnt]);
    	else
    	{
    		z++;
    		if(a[cnt]!=z&&cnt>num)
    		{
    			ans++;
    			num=cnt-1;
    		}
			cnt--;
    		num=min(num,cnt);
    	}//234546
    }//123456
    cout<<ans;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define MAXN 300005
#define GET c=getchar()
#define SHU ('0'<=c&c<='9')
#define ll long long
using namespace std;
ll n,m,t,x,y,z,cnt,awfa,ans;
ll a[MAXN];
string s;

int main()
{
    cin>>n;
    for(ll i=1;i<=2*n;i++)
    {
    	cin>>s;
    	if(s[0]=='a') scanf("%lld",&a[++cnt]);
    	else
    	{
    		z++;
    		if(a[cnt]!=z&&cnt>x)
    		{
    			ans++;
    			x=cnt-1;
    		}
    		x=min(x,--cnt);
    	}
    }//123456
    cout<<ans;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional>

#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))

using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
//const int mod = 1e9+7;
const int maxn = 2e5+100;
const int maxm = 2e6+100;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);

stack<int>s;
int main(){
    int n;
    scanf("%d", &n);
    int tmp = 1;
    int ans = 0;
    for(int i = 0; i < 2*n; i++){
        char c[10];
        scanf("%s",c);
        if(c[0]=='a'){
            int x;
            scanf("%d", &x);
            s.push(x);
        }
        else{

            if(s.empty());
            else if(s.top()==tmp)s.pop();
            else {
                ans++;
                while(!s.empty())s.pop();
            }

            tmp++;
        }
    }
    printf("%d",ans);
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <climits>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <ctime>
#include <ctype.h>

#define INF 0x3f3f3f3f
#define EXP 1e-8
#define MEM(a,x) memset(a,x,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define LL long long
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _fore(i,a,b) for(int i = (a); i <= (b); i++)
const double PI = acos(-1.0);

using namespace std;

int main() {
    char str[10];
    vector<int> vec;
    int n, cnt = 1, ans = 0;
    cin >> n;
    for(int i = 1; i <= 2 * n; i++) {
        cin >> str;
        if(str[0] == 'a') {
            int temp;
            cin >> temp;
            vec.push_back(temp);
        } else {
            if(vec.empty());
            else if(vec.back() == cnt)
                vec.pop_back();
            else
                ans++, vec.clear();
            cnt++;
        }
    }
    cout << ans << endl;
}
//...


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define MAXN 300005
#define GET c=getchar()
#define SHU ('0'<=c&c<='9')
#define ll long long
using namespace std;
ll n,m,t,x,y,z,cnt,ans;
ll a[MAXN];
string s;

int main()
{
    cin>>n;
    for(ll i=1;i<=2*n;i++)
    {
    	cin>>s;
    	if(s[0]=='a') scanf("%lld",&a[++cnt]);
    	else
    	{
    		z++;
    		if(a[cnt]!=z&&cnt>x)
    		{
    			ans++;
    			x=cnt-1;
    		}
    		x=min(x,--cnt);
    	}
    }//123
    cout<<ans;
    return 0;
}


#include <iostream>
#include <stack>
#include <string>
using namespace std;
stack<int> boxes;
string com;
int l;
int ans = 0;
int toberem = 1;
int n;
int main() {
	cin >> n;
	for (int i = 0; i < 2 * n; i++) {
		cin >> com;
		if (com == "add") {
			cin >> l;
			boxes.push(l);
		}
		else {
			if (!boxes.empty() && boxes.top() == toberem)
				boxes.pop();
			else if (boxes.empty()) {}
			else {
				ans++;
				while (!boxes.empty())
					boxes.pop();
			}
			toberem++;
		}
	}
	cout << ans << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool comp(const int a, const int b)
{
	return a > b;
}

int main()
{
	vector <int> V;

	int n, a, remove = 1, kol = 0, i;
	string s;

	cin >> n;

	for (i = 0; i < 2 * n; i++)
	{
		cin >> s;

		if (s == "add")
		{
			cin >> a;
			V.push_back(a);
		}

		else
		{
			a = V.back();

			if (a == remove) V.erase(V.begin() + V.size() - 1);

			else
			{
				kol++;
				sort(V.begin(), V.end(), comp);
				V.erase(V.begin() + V.size() - 1);
			}

			remove++;
		}
	}

	cout << kol;

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <stack>

using namespace std;

stack <int> S;
vector <int> V;

int f(int a)
{
	int flag = 0, i;

	for (i = 0; i < V.size() && !flag; i++)
		if (V[i] == a)
		{
			flag = 1;
			V[i] = -1;
		}

		return flag;
}

int main()
{
	string s;
	int n, a, i, j, remove = 1, kol = 0;

	cin >> n;

	for (i = 0; i < n*2; i++)
	{
		cin >> s;

		if (s == "add")
		{
			cin >> a;
			S.push(a);

			for (j = 0; j < V.size(); j++) if(V[j] != -1) S.push(V[j]);
			V.clear();

		}

		else
		{
			if(!S.empty()) a = S.top();

			if (remove != a && !f(remove))
			{
				kol++;

				while (remove != a)
				{
					V.push_back(a);
					S.pop();
					a = S.top();
				}

				S.pop();
			}

			else if (remove != a) i++;

			else if(a == remove) S.pop();

			remove++;
		}
	}

	cout << kol;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>

using namespace std;

stack <int> S;
vector <int> V;

int f(int a)
{
	int flag = 0, i;

	for (i = 0; i < V.size() && !flag; i++)
		if (V[i] == a)
		{
			flag = 1;
			V[i] = -1;
		}

		return flag;
}

int main()
{
	string s;
	int n, a, i, j, remove = 1, kol = 0;

	cin >> n;

	for (i = 0; i < n*2; i++)
	{
		cin >> s;

		if (s == "add")
		{
			cin >> a;
			S.push(a);
			if (!V.empty()) sort(V.begin(), V.end());
			for (j = 0; j < V.size(); j++) if(V[j] != -1) S.push(V[j]);
			V.clear();

		}

		else
		{
			if(!S.empty()) a = S.top();

			if (remove != a && !f(remove))
			{
				kol++;

				while (remove != a)
				{
					V.push_back(a);
					S.pop();
					a = S.top();
				}

				S.pop();
			}

			else if(a == remove) S.pop();

			remove++;
		}
	}

	cout << kol;

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <stack>

using namespace std;

stack <int> S;
vector <int> V;

int f(int a)
{
	int flag = 0, i;

	for (i = 0; i < V.size() && !flag; i++)
		if (V[i] == a)
		{
			flag = 1;
			V[i] = -1;
		}

		return flag;
}

int main()
{
	string s;
	int n, a, i, j, remove = 1, kol = 0;

	cin >> n;

	for (i = 0; i < n*2; i++)
	{
		cin >> s;

		if (s == "add")
		{
			cin >> a;
			S.push(a);

			for (j = 0; j < V.size(); j++) if(V[j] != -1) S.push(V[j]);
			V.clear();

		}

		else
		{
			if(!S.empty()) a = S.top();

			if (remove != a && !f(remove))
			{
				kol++;

				while (remove != a)
				{
					V.push_back(a);
					S.pop();
					a = S.top();
				}

				S.pop();
			}

			else if(a == remove) S.pop();

			remove++;
		}
	}

	cout << kol;

	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool comp(const int a, const int b)
{
	return a > b;
}

int main()
{
	vector <int> V;

	int n, a, remove = 1, kol = 0, i;
	string s;

	cin >> n;

	for (i = 0; i < 2 * n; i++)
	{
		cin >> s;

		if (s == "add")
		{
			cin >> a;
			V.push_back(a);
		}

		else
		{
			if (!V.empty())
			{
				a = V.back();

				if (a == remove) V.erase(V.begin() + V.size() - 1);

				else
				{
					kol++;
					V.clear();
				}
			}

			remove++;
		}
	}

	cout << kol;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>

using namespace std;

stack <int> S;
vector <int> V;

int main()
{
	string s;
	int n, a, i, j, remove = 1, kol = 0;

	cin >> n;

	for (i = 0; i < n*2; i++)
	{
		cin >> s;

		if (s == "add")
		{
			cin >> a;
			S.push(a);
		}

		else
		{
			a = S.top();

			if (remove != a)
			{
				kol++;

				while (true)
				{
					if (a != remove) V.push_back(a);
					S.pop();
					if (S.empty()) break;
					a = S.top();
				}

				if(!V.empty()) sort(V.begin(), V.end());
				for (j = V.size() - 1; j >= 0; j--) S.push(V[j]);

				V.clear();
			}

			else S.pop();

			remove++;
		}
	}

	cout << kol;

	return 0;
}


#include<cstdio>
#include<stack>
#include<string>
#include<iostream>
#define ll long long
using namespace std;
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		stack<int> st;
		string str;
		int cur=1;
		ll ans=0;
		for(int i=0;i<2*n;i++)
		{
			cin>>str;
			if(str[0]=='a')
			{
				int x;
				cin>>x;
				st.push(x);
			}
			else if(str[0]=='r')
			{
				if(!st.empty())
				{
					if(cur==st.top())
					st.pop();
					else
					{
						ans++;
						while(!st.empty())st.pop();
					}
				}
				cur++;
			}
		}
		printf("%I64d\n",ans);
	}
}


//
//  main.cpp
//  f-CF-Codeforces Round #420 (Div. 2)-C-Okabe and Boxes
//
//  Created by ZYJ on 2017/6/27.
//  Copyright © 2017年 ZYJ. All rights reserved.
//

#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

char str[7];
vector<int> vi;

int n;

int main()
{
    scanf("%d", &n);

    int cnt = 1, ans = 0, x;
    for (int i = 1; i <= 2 * n; i++)
    {
        scanf("%s", str);
        if (str[0] == 'a')
        {
            scanf("%d", &x);
            vi.push_back(x);
        }
        else
        {
            if (vi.empty()) ;
            else if (vi.back() == cnt)
            {
                vi.pop_back();
            }
            else
            {
                ans++;
                vi.clear();
            }
            cnt++;
        }
    }

    cout << ans << endl;

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crtdbg.h>
#include <ctype.h>
#include <math.h>

#define min(a,b) (((a)<(b)) ? (a) : (b))
#define max(a,b) (((a)>(b)) ? (a) : (b))

int compare(const void * x1, const void * x2)
{
	return -(*(int*)x1 - *(int*)x2);
}

int main(void)
{
	int *a, *b, n, size = 0, top = 1, ans = 0, isWas = 0, afterWas = 0;
	char s[100];
	scanf("%d", &n);
	a = (int*)malloc(sizeof(int) * n);
	b = (int*)malloc(sizeof(int) * (n + 1));
	for (int i = 0; i < (n * 2); i++)
	{
		scanf("%s", s);
		if (s[0] == 'a')
		{
			size++;
			scanf("%d", &a[size - 1]);
			b[a[size - 1]] = size - 1;
			if (isWas == 1)
			{
				afterWas++;
			}
		}
		else
		{
			if (top == a[size - 1])
			{
				if (isWas == 1 && afterWas > 0)
				{
					afterWas = max(0, afterWas - 1);
				}
				size--;
				top++;
			}
			else
			{
				if (isWas == 0)
				{
					isWas = 1;
					afterWas = 0;
					int indTop = b[top];
					int tmp = a[indTop];
					a[indTop] = a[size - 1];
					a[size - 1] = tmp;
					top++;
					size--;
					ans++;
				}
				else
				{
					if (afterWas == 0)
					{
						size--;
						top++;
					}
					else
					{
						isWas = 1;
						afterWas = 0;
						int indTop = b[top];
						int tmp = a[indTop];
						a[indTop] = a[size - 1];
						a[size - 1] = tmp;
						top++;
						size--;
						ans++;
					}
				}
			}
		}
	}
	printf("%d\n", ans);
	free(a);
	free(b);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crtdbg.h>
#include <ctype.h>
#include <math.h>

#define min(a,b) (((a)<(b)) ? (a) : (b))
#define max(a,b) (((a)>(b)) ? (a) : (b))

int compare(const void * x1, const void * x2)
{
	return -(*(int*)x1 - *(int*)x2);
}

int main(void)
{
	int *a, n, size = 0, top = 1, ans = 0;
	char s[100];
	scanf("%d", &n);
	a = (int*)malloc(sizeof(int) * n);
	for (int i = 0; i < (n * 2); i++)
	{
		scanf("%s", s);
		if (s[0] == 'a')
		{
			size++;
			scanf("%d", &a[size - 1]);
		}
		else
		{
			if (top == a[size - 1])
			{
				size--;
				top++;
			}
			else
			{
				qsort(a, size, sizeof(int), compare);
				size--;
				top++;
				ans++;
			}
		}
	}
	printf("%d\n", ans);
	free(a);
	return 0;
}


#include "stdio.h"
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <functional>
#define MAXN 50
#define MAXT 524288
#define S 524287
#define INF 0x0fffffff
using namespace std;
typedef long long ll;
int N;
char buf[10];
int num, r;
priority_queue<int, vector<int>, greater<int>> pq;
int main()
{
	scanf("%d", &N);
	int ans = 0;
	for (int i = 0;i < 2 * N;i++)
	{
		scanf("%s", buf);
		if (buf[0] == 'a') {
			scanf("%d", &num);
			if (pq.empty()) r = 1000000;
			else if (pq.top() > num) r++;
			else r = 1;
			pq.push(num);
		}
		else {
			if (r <= 1) ans++, r = 1000000;
			else r--, pq.pop();
		}
	}
	printf("%d\n", ans);
}


#include "stdio.h"
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <functional>
#define MAXN 50
#define MAXT 524288
#define S 524287
#define INF 0x0fffffff
using namespace std;
typedef long long ll;
int N;
char buf[10];
int num, r;
priority_queue<int, vector<int>, greater<int>> pq;
int main()
{
	scanf("%d", &N);
	int ans = 0;
	for (int i = 0;i < 2 * N;i++)
	{
		scanf("%s", buf);
		if (buf[0] == 'a') {
			scanf("%d", &num);
			if (pq.empty()) r = 1000000;
			else if (pq.top() > num) r++;
			else r = 1;
			pq.push(num);
		}
		else {
			if (r <= 1) ans++, r = 1000000;
			else r--;
			pq.pop();
		}
	}
	printf("%d\n", ans);
}


#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
using namespace std;

int main(void)
{

	int n,number,sum,x;
	char str[10];
	vector<int>p;

	scanf("%d",&n);

	sum=0;
	x=1;

	for(int i=0;i<2*n;i++){

		scanf("%s",str);

		if(str[0]=='a'){
			scanf("%d",&number);
			p.push_back(number);
		}
		else{

			if(p.empty()){
			}
			else if(p.back()==x){
				p.pop_back();
			}
			else{
				sum++;
				p.clear();
			}
			x++;
		}

	}

	printf("%d",sum);

}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<queue>
#include <fstream>
#include<map>
#include<stack>
using namespace std;
#define ll long long
int dr[] = { 0,1,0,-1 };
int dc[] = { 1,0,-1,0 };
stack<int>s;
set<int>ste;
int g[300001];
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif // !ONLINE_JUDGE
	int n;
	char st[50];
	scanf("%d", &n);
	bool needSort = false;
	int lastNum = -1;
	int num = 1;
	int sum = 0;
	vector<int>tmp;
	for (int i = 0,x; i < 2*n; ++i) {
		scanf("%s%d", st, &x);
		if (st[0] == 'a') {
			if (!s.empty() && x > s.top()) {
				tmp.push_back(x);
				while (!s.empty()) {
					tmp.push_back(s.top());
					s.pop();
				}
			}
			else
				s.push(x);
		}
		else {
			if (!s.empty() && s.top() == num) {
				num++;
				s.pop();
			}
			else {
				if (s.empty() && ste.find(num)!=ste.end())
					num++;
				else {
					sum++;
					while (!s.empty()) {
						tmp.push_back(s.top());
						s.pop();
					}
					for (int j = 0; j < tmp.size(); ++j)
						ste.insert(tmp[j]);
					num++;
					tmp.clear();
				}
			}
		}
	}
	cout << sum << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<queue>
#include <fstream>
#include<map>
#include<stack>
using namespace std;
#define ll long long
int dr[] = { 0,1,0,-1 };
int dc[] = { 1,0,-1,0 };
stack<int>s;
set<int>ste;
vector<int>tmp;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif // !ONLINE_JUDGE
	int n;
	char st[50];
	scanf("%d", &n);
	int num = 1;
	int sum = 0;
	for (int i = 0,x; i < 2*n; ++i) {
		scanf("%s%d", st, &x);
		if (st[0] == 'a') {
			if (!s.empty() && x > s.top()) {
				tmp.push_back(x);
				while (!s.empty()) {
					tmp.push_back(s.top());
					s.pop();
				}
			}
			else
				s.push(x);
		}
		else {
			if (!s.empty() && s.top() == num) {
				num++;
				s.pop();
			}
			else {
				if (s.empty() && ste.find(num)!=ste.end())
					num++;
				else {
					sum++;
					while (!s.empty()) {
						tmp.push_back(s.top());
						s.pop();
					}
					for (int j = 0; j < tmp.size(); ++j)
						ste.insert(tmp[j]);
					num++;
					tmp.clear();
				}
			}
		}
	}
	cout << sum << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<queue>
#include <fstream>
#include<map>
#include<stack>
using namespace std;
#define ll long long
int dr[] = { 0,1,0,-1 };
int dc[] = { 1,0,-1,0 };
stack<int>s;
set<int>ste;
int g[300001];
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif // !ONLINE_JUDGE
	int n;
	char st[50];
	scanf("%d", &n);
	bool needSort = false;
	int lastNum = -1;
	int num = 1;
	int sum = 0;
	vector<int>tmp;
	for (int i = 0,x; i < 2*n; ++i) {
		scanf("%s%d", st, &x);
		if (st[0] == 'a') {
			if (!s.empty() && x > s.top()) {
				tmp.push_back(x);
				while (!s.empty()) {
					tmp.push_back(s.top());
					s.pop();
				}
			}
			else
				s.push(x);
			lastNum = max(lastNum, x);
		}
		else {
			if (!s.empty() && s.top() == num)
				num++;
			else {
				if (s.empty() && ste.find(num)!=ste.end())
					num++;
				else {
					sum++;
					while (!s.empty()) {
						tmp.push_back(s.top());
						s.pop();
					}
					for (int j = 0; j < tmp.size(); ++j)
						ste.insert(tmp[j]);
					num++;
					tmp.clear();
				}
			}
		}
	}
	cout << sum << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<queue>
#include <fstream>
#include<map>
#include<stack>
using namespace std;
#define ll long long
int dr[] = { 0,1,0,-1 };
int dc[] = { 1,0,-1,0 };
stack<int>s;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif // !ONLINE_JUDGE
	int n;
	char s[50];
	scanf("%d", &n);
	bool needSort = false;
	int lastNum = -1;
	int sum = 0;
	for (int i = 0,x; i < 2*n; ++i) {
		scanf("%s%d", s, &x);
		if (s[0] == 'a') {
			if (lastNum != -1 && x > lastNum)
				needSort = true;
			lastNum = x;
		}
		else {
			if (needSort) {
				sum++;
				lastNum = -1;
			}
			needSort = false;
		}
	}
	cout << sum << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<queue>
#include <fstream>
#include<map>
#include<stack>
using namespace std;
#define ll long long
int dr[] = { 0,1,0,-1 };
int dc[] = { 1,0,-1,0 };
stack<int>s;
set<int>ste;
vector<int>tmp;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif // !ONLINE_JUDGE
	int n;
	char st[50];
	scanf("%d", &n);
	int num = 1;
	int sum = 0;
	for (int i = 0,x; i < 2*n; ++i) {
		scanf("%s%d", st, &x);
		if (st[0] == 'a') {
			if (!s.empty() && x > s.top()) {
				tmp.push_back(x);
				while (!s.empty()) {
					tmp.push_back(s.top());
					s.pop();
				}
			}
			else
				s.push(x);
		}
		else {
			if (!s.empty() && s.top() == num) {
				num++;
				s.pop();
			}
			else {
				if (tmp.size()==0 && s.empty() && ste.find(num)!=ste.end())
					num++;
				else {
					sum++;
					while (!s.empty()) {
						tmp.push_back(s.top());
						s.pop();
					}
					for (int j = 0; j < tmp.size(); ++j)
						ste.insert(tmp[j]);
					num++;
					tmp.clear();
				}
			}
		}
	}
	cout << sum << endl;
}


//G
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<stack>
using namespace std;
#define MAXN 300010

stack<int>S;
string s;

int main()
{
    int i;
    int ans,cnt;
    int temp;
    int n;
    int x;

    while(scanf("%d",&n)!=EOF)
    {
        ans=cnt=0;
        while(!S.empty())
            S.pop();
        for(i=1;i<=2*n;i++)
        {
            s.clear();
            cin>>s;
            if(s[0]=='a')
            {
                scanf("%d",&x);
                S.push(x);
            }
            else
            {
                ++cnt;
                if(S.empty())
                    continue;
                temp=S.top();
                if(temp==cnt)
                {
                    if(!S.empty())
                        S.pop();
                }
                else
                {
                    ans++;
                    while(!S.empty())
                        S.pop();
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std;
int a[500000],ans[500000],stk[500000],stk_top,a_len;
int n,m;
char s[10];
int main()
{
	stk_top=-1;
	a_len=0;
	scanf("%d",&n);
	for (int i=0;i<2*n;++i){
		scanf("%*c%s",&s);
		if (s[0]=='a') {
			scanf("%d",&m);
			stk[++stk_top]=m;
		}
		else {
			a[a_len++]=stk[stk_top--];
		}

	}
	int len=1,left,right;
	ans[0]=a[0];
	for (int i=1;i<n;++i){
		if (a[i]>ans[len-1]){
			ans[len++]=a[i];
		}
		else {
			left=0;right=len-1;
		    while (left<=right)
			{
				int mid=(left+right)/2;
				if (ans[mid]<=a[i]) left=mid+1;
				else right=mid-1;
			}
			ans[left]=a[i];

		}
	}
	cout<<n-len<<endl;
}


#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std;
int ans,stk[500000],stk_top,a_len,top;
int n,m;
char s[10];
int main()
{
	stk_top=0;
	top=1;
	a_len=0;
	ans=0;
	scanf("%d",&n);
	for (int i=0;i<2*n;++i){
		scanf("%*c%s",&s);
		if (s[0]=='a') {
			scanf("%d",&m);
			stk[++stk_top]=m;
		}
		else {
		   if (stk_top==0);
		   else
           if (stk[stk_top]==top)
			   stk_top--;
		   else {
			   stk_top=0;
			   ans++;
		   }
           top++;
		}
	}
	cout<<ans<<endl;
}


#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

vector<int> a;

int find(int cur){
	int ans = 0;
	int min = 1000000000;
	for (int i = 0; i < a.size(); ++i){
		if(a[i] > cur){
			if (a[i] - cur < min){
				ans = a[i];
				min = a[i] - min;
			}
		}
	}
	return ans;
}

int main() {
	int n, ans = 0, cur_rem = 1;
	stack<int> st;
	cin >> n;
	string s;
	int num;
	bool flag = false;
	for (int i = 0; i < 2*n; ++i){
		s = "";
		cin >> s;
		if (flag){
			if(s == "remove")
				continue;
		}
		if (s == "add"){
			flag = false;
			cin >> num;
			st.push(num);
			a.push_back(num);
		}
		else{
			if (st.top() == cur_rem){
				st.pop();
				cur_rem += 1;
			}
			else{
				if(st.top() < cur_rem){
					cur_rem += 1;
				}
				else{
					flag = true;
					st.top() = find(cur_rem);
					cur_rem += 1;
					ans += 1;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

vector<int> a;

int find(int cur){
	int ans = 0;
	int min = 1000000000;
	for (int i = 0; i < a.size(); ++i){
		if(a[i] > cur){
			if (a[i] - cur < min){
				ans = a[i];
				min = a[i] - min;
			}
		}
	}
	return ans;
}

int main() {
	int n, ans = 0, cur_rem = 1;
	stack<int> st;
	cin >> n;
	string s;
	int num;
	for (int i = 0; i < 2*n; ++i){
		s = "";
		cin >> s;
		if (s == "add"){
			cin >> num;
			st.push(num);
			a.push_back(num);
		}
		else{
			if (st.top() == cur_rem){
				st.pop();
				cur_rem += 1;
			}
			else{
				if(st.top() < cur_rem){
					cur_rem += 1;
				}
				else{
					st.top() = find(cur_rem);
					cur_rem += 1;
					ans += 1;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author codeKNIGHT
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	public void solve(int testNumber, Scanner in, PrintWriter out) {
        int n=in.nextInt(),i,k=in.nextInt();
        int a[]=new int[n];
        for(i=0;i<n;i++)
            a[i]=in.nextInt();
        Arrays.sort(a);
        int pos=(n+1)/2,c=0;
        if(a[pos-1]==k)
        {
            out.println(0);
            return;
        }
        if(a[pos-1]>k)
        {
            int d=(n+1)/2,z=-1;
            for(i=0;i<n;i++)
            {
                if(a[i]==k)
                    z=i;
            }
             pos=z+1;
           while (d!=pos)
           {
               pos++;
               n++;
               d=(n+1)/2;
               c++;
           }
        }
        else
        {
            int d=(n+1)/2,z=n;
            for(i=n-1;i>=0;i--)
                if(a[i]==k)
                    z=k;
            pos=z+1;
            while (d!=pos)
            {
                n++;
                d=(n+1)/2;
                c++;
            }
        }
        out.println(c);
	}
}


import java.util.List;
import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author codeKNIGHT
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	public void solve(int testNumber, Scanner in, PrintWriter out) {
        int n=in.nextInt(),i,k=in.nextInt();
        ArrayList<Integer> a=new ArrayList<Integer>();
        //int a[]=new int[n+1];
        for(i=0;i<n;i++)
            a.add(in.nextInt());
        Collections.sort(a);
        int pos=(n+1)/2,c=1;
        if(a.get(pos-1)==k)
        {
            out.println(0);
            return;
        }
        a.add(k);
        Collections.sort(a);
        n++;
        pos=(n+1)/2;
        if(a.get(pos-1)>=k)
        {
            int d=(n+1)/2,z=-1;
            for(i=0;i<n;i++)
            {
                if(a.get(i)==k)
                    z=i;
            }
             pos=z+1;
           while (d!=pos)
           {
               pos++;
               n++;
               d=(n+1)/2;
               c++;
           }
        }
        else
        {
            int d=(n+1)/2,z=n;
            for(i=n-1;i>=0;i--)
                if(a.get(i)==k)
                    z=i;
            pos=z+1;
            while (d!=pos)
            {
                n++;
                d=(n+1)/2;
                c++;
            }
        }
        out.println(c);
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution{

    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

/*      public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }
*/
        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }
        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }

    ////////////////////////////////////////////////////////////////////
    //      Number Theory

    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;
        }
        return x;
    }

    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;

        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }

    void findSubsets(int array[]){

        long numOfSubsets = 1 << array.length;
        for(int i = 0; i < numOfSubsets; i++){

            int pos = array.length - 1;
            int bitmask = i;

            while(bitmask > 0){
                if((bitmask & 1) == 1)
                    ww.print(array[pos]+" ");

                bitmask >>= 1;
                pos--;
            }

            ww.println();
        }
    }

    public static int gcd(int a, int b){
        return b == 0 ? a : gcd(b,a%b);
    }

    public static int lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }

    public static int lcm(int a, int b){
        return a*b/gcd(a,b);
    }

    ////////////////////////////////////////////////////////////////////

//    private static    FastScanner s = new FastScanner(new File("input.txt"));
//    private static PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    InputStream inputStream = System.in;
    FastScanner s = new FastScanner(inputStream);
    OutputStream outputStream = System.out;
    PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };

    ////////////////////////////////////////////////////////////////////

    public static void main(String[] args) throws IOException{
        new Solution().solve();
    }

    ////////////////////////////////////////////////////////////////////

    void solve() throws IOException{

        int n = s.nextInt();
        int key = s.nextInt();
        Integer[] a = new Integer[n];
        for(int i=0;i<n;i++) a[i] = s.nextInt();

        Arrays.sort(a);
        int mid = (n)/2 + n&1;
        int in = Arrays.binarySearch(a, key);

        if(in < 0){
            in = Math.abs(in);
            if(in > n) ww.println(n+1);
            else if(in == mid) ww.println(0);
            else if(in < mid) ww.println(Math.abs(in-mid));
            else ww.println(Math.abs(in*2-1-n));
        }else {
            in++;
            if(in > n) ww.println(n+1);
            else if(in == mid) ww.println(0);
            else if(in < mid) ww.println(Math.abs(in-mid));
            else ww.println(Math.abs(in*2-1-n));
        }

        s.close();
        ww.close();
     }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution{

    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

/*      public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }
*/
        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }
        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }

    ////////////////////////////////////////////////////////////////////
    //      Number Theory

    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;
        }
        return x;
    }

    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;

        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }

    void findSubsets(int array[]){

        long numOfSubsets = 1 << array.length;
        for(int i = 0; i < numOfSubsets; i++){

            int pos = array.length - 1;
            int bitmask = i;

            while(bitmask > 0){
                if((bitmask & 1) == 1)
                    ww.print(array[pos]+" ");

                bitmask >>= 1;
                pos--;
            }

            ww.println();
        }
    }

    public static int gcd(int a, int b){
        return b == 0 ? a : gcd(b,a%b);
    }

    public static int lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }

    public static int lcm(int a, int b){
        return a*b/gcd(a,b);
    }

    ////////////////////////////////////////////////////////////////////

//    private static    FastScanner s = new FastScanner(new File("input.txt"));
//    private static PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    InputStream inputStream = System.in;
    FastScanner s = new FastScanner(inputStream);
    OutputStream outputStream = System.out;
    PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };

    ////////////////////////////////////////////////////////////////////

    public static void main(String[] args) throws IOException{
        new Solution().solve();
    }

    ////////////////////////////////////////////////////////////////////

    void solve() throws IOException{

        int n = s.nextInt();
        int key = s.nextInt();
        Integer[] a = new Integer[n];
        for(int i=0;i<n;i++) a[i] = s.nextInt();

        Arrays.sort(a);
        int in = Arrays.binarySearch(a, key);

        if(in < 0){
            in = Math.abs(in);
            ww.println(Math.abs((in*2)-1-n));
        }else {
            in++;
            ww.println(Math.abs((in*2)-1-n));
        }

        s.close();
        ww.close();
     }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution{

    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

/*      public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }
*/
        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }
        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }

    ////////////////////////////////////////////////////////////////////
    //      Number Theory

    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;
        }
        return x;
    }

    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;

        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }

    void findSubsets(int array[]){

        long numOfSubsets = 1 << array.length;
        for(int i = 0; i < numOfSubsets; i++){

            int pos = array.length - 1;
            int bitmask = i;

            while(bitmask > 0){
                if((bitmask & 1) == 1)
                    ww.print(array[pos]+" ");

                bitmask >>= 1;
                pos--;
            }

            ww.println();
        }
    }

    public static int gcd(int a, int b){
        return b == 0 ? a : gcd(b,a%b);
    }

    public static int lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }

    public static int lcm(int a, int b){
        return a*b/gcd(a,b);
    }

    ////////////////////////////////////////////////////////////////////

//    private static    FastScanner s = new FastScanner(new File("input.txt"));
//    private static PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    InputStream inputStream = System.in;
    FastScanner s = new FastScanner(inputStream);
    OutputStream outputStream = System.out;
    PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };

    ////////////////////////////////////////////////////////////////////

    public static void main(String[] args) throws IOException{
        new Solution().solve();
    }

    ////////////////////////////////////////////////////////////////////

    void solve() throws IOException{

        int n = s.nextInt();
        int key = s.nextInt();
        Integer[] a = new Integer[n];
        for(int i=0;i<n;i++) a[i] = s.nextInt();

        Arrays.sort(a);
        int mid = (n+1)/2;
        int in = Arrays.binarySearch(a, key);

        if(in < 0){
            in = Math.abs(in);
            if(in > n) ww.println(n+1);
            else if(in == mid) ww.println(0);
            else if(in < mid) ww.println(Math.abs(in-mid));
            else ww.println(Math.abs(in*2-1-n));
        }else {
            in++;
            if(in > n) ww.println(n+1);
            else if(in == mid) ww.println(0);
            else if(in < mid) ww.println(Math.abs(in-mid));
            else ww.println(Math.abs(in*2-1-n));
        }

        s.close();
        ww.close();
     }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution{

    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

/*      public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }
*/
        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }
        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }

    ////////////////////////////////////////////////////////////////////
    //      Number Theory

    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;
        }
        return x;
    }

    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;

        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }

    void findSubsets(int array[]){

        long numOfSubsets = 1 << array.length;
        for(int i = 0; i < numOfSubsets; i++){

            int pos = array.length - 1;
            int bitmask = i;

            while(bitmask > 0){
                if((bitmask & 1) == 1)
                    ww.print(array[pos]+" ");

                bitmask >>= 1;
                pos--;
            }

            ww.println();
        }
    }

    public static int gcd(int a, int b){
        return b == 0 ? a : gcd(b,a%b);
    }

    public static int lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }

    public static int lcm(int a, int b){
        return a*b/gcd(a,b);
    }

    ////////////////////////////////////////////////////////////////////

//    private static    FastScanner s = new FastScanner(new File("input.txt"));
//    private static PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    InputStream inputStream = System.in;
    FastScanner s = new FastScanner(inputStream);
    OutputStream outputStream = System.out;
    PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };

    ////////////////////////////////////////////////////////////////////

    public static void main(String[] args) throws IOException{
        new Solution().solve();
    }

    ////////////////////////////////////////////////////////////////////

    void solve() throws IOException{

        int n = s.nextInt();
        int key = s.nextInt();
        Integer[] a = new Integer[n];
        for(int i=0;i<n;i++) a[i] = s.nextInt();

        Arrays.sort(a);
        int mid = (n+1)/2;
        int in = Arrays.binarySearch(a, key);

        if(in < 0) ww.println(n+1);
        else{
            in++;
            if(in == mid) ww.println(0);
            else ww.println(Math.abs(mid-in));
        }

        s.close();
        ww.close();
     }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution{

    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

/*      public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }
*/
        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }
        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }

    ////////////////////////////////////////////////////////////////////
    //      Number Theory

    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;
        }
        return x;
    }

    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;

        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }

    void findSubsets(int array[]){

        long numOfSubsets = 1 << array.length;
        for(int i = 0; i < numOfSubsets; i++){

            int pos = array.length - 1;
            int bitmask = i;

            while(bitmask > 0){
                if((bitmask & 1) == 1)
                    ww.print(array[pos]+" ");

                bitmask >>= 1;
                pos--;
            }

            ww.println();
        }
    }

    public static int gcd(int a, int b){
        return b == 0 ? a : gcd(b,a%b);
    }

    public static int lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }

    public static int lcm(int a, int b){
        return a*b/gcd(a,b);
    }

    ////////////////////////////////////////////////////////////////////

//    private static    FastScanner s = new FastScanner(new File("input.txt"));
//    private static PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    InputStream inputStream = System.in;
    FastScanner s = new FastScanner(inputStream);
    OutputStream outputStream = System.out;
    PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };

    ////////////////////////////////////////////////////////////////////

    public static void main(String[] args) throws IOException{
        new Solution().solve();
    }

    ////////////////////////////////////////////////////////////////////

    void solve() throws IOException{

        int n = s.nextInt();
        int key = s.nextInt();
        Integer[] a = new Integer[n];
        for(int i=0;i<n;i++) a[i] = s.nextInt();

        Arrays.sort(a);
        int mid = (n+1)/2;
        int in = Arrays.binarySearch(a, key);

        if(in < 0){
            in = Math.abs(in);
            if(in > n) ww.println(n+1);
            else if(in < mid) ww.println(Math.abs(in-mid));
            else ww.println(Math.abs(in*2-1-n));
        }else {
            in++;
            if(in > n) ww.println(n+1);
            else if(in < mid) ww.println(Math.abs(in-mid));
            else ww.println(Math.abs(in*2-1-n));
        }

        s.close();
        ww.close();
     }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution{

    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

/*      public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }
*/
        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }
        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }

    ////////////////////////////////////////////////////////////////////
    //      Number Theory

    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;
        }
        return x;
    }

    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;

        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }

    void findSubsets(int array[]){

        long numOfSubsets = 1 << array.length;
        for(int i = 0; i < numOfSubsets; i++){

            int pos = array.length - 1;
            int bitmask = i;

            while(bitmask > 0){
                if((bitmask & 1) == 1)
                    ww.print(array[pos]+" ");

                bitmask >>= 1;
                pos--;
            }

            ww.println();
        }
    }

    public static int gcd(int a, int b){
        return b == 0 ? a : gcd(b,a%b);
    }

    public static int lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }

    public static int lcm(int a, int b){
        return a*b/gcd(a,b);
    }

    ////////////////////////////////////////////////////////////////////

//    private static    FastScanner s = new FastScanner(new File("input.txt"));
//    private static PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    InputStream inputStream = System.in;
    FastScanner s = new FastScanner(inputStream);
    OutputStream outputStream = System.out;
    PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };

    ////////////////////////////////////////////////////////////////////

    public static void main(String[] args) throws IOException{
        new Solution().solve();
    }

    ////////////////////////////////////////////////////////////////////

    void solve() throws IOException{

        int n = s.nextInt();
        int key = s.nextInt();
        Integer[] a = new Integer[n];
        for(int i=0;i<n;i++) a[i] = s.nextInt();

        Arrays.sort(a);
        int mid = (n+1)/2;
        int in = Arrays.binarySearch(a, key);

        if(in < 0){
            in = Math.abs(in);
            if(in > n) ww.println(n+1);
            else ww.println(Math.abs(in-mid));
        }else {
            if(in > n) ww.println(n+1);
            else ww.println(Math.abs(in-mid));
        }

        s.close();
        ww.close();
     }

}