#include <bits/stdc++.h>

using namespace std;

#define MAXN 200010

int n, a[MAXN];
bool vis[MAXN];

void read(){
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", a + i);
    sort(a + 1, a + 1 + n);
}

int solve(int l, int r, int k){
    if(l >= r) return 0;

    int mid;
    for(mid = l; mid <= r; ++mid)
        if(a[mid] >> k & 1)
            break;

    int res1 = solve(l, mid - 1, k - 1);
    int res2 = solve(mid, r, k - 1);
    return min(res1 + max(0, r - mid), res2 + max(0, mid - l - 1));
}

int main(){
    read();
    printf("%d\n", solve(1, n, 30));
    return 0;
}


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

using namespace std;

#define v vector
#define pi pair<int, int>
#define ll long long

// Given A, find min A XOR B

// Well, it should be less than num bits A
// Otherwise we get bigger.
// So
//  1) Cancel out biggest bit
//  2) Cancel out next bit
//  3) ...

// Algo:
// Things starting with my bit
// If something, thats my gang
// Otherwise (nobody), concede that bit.
//

// OBSERVATION 1:
// EXACTLY ONE PAIR MUST BE EQUALS OF EACH OTHER
// SO THAT EDGE COUNT = N-1

// OBSERVATION 2:
// CANNOT HAVE ANY CYCLES

// 1) Get all dual pair mins
// 2) Remove one of each.....

// ...
// Removing can create more pairs though.
//

// For all pairs,
// If one of them can be removed with no DRAMA. Then do it, and increment count.
// ...
// Might not always be for the best...
// GOD DAMNIT.

// WHAT CHANGES IN THE GRAPH?
// WHEN WE DELETE SOMETHING, EVERYTHING GOING IN TO IT CHOOSES A NEW NODE.
// THIS IS BAD IF IT GOES TO SOMETHING WHICH WAS GOING INTO *THAT* EARLIER.

// Look.
// For every bit pattern, there's this cycle.
// And we can basically join it up

// NTS just store a nlogn map of substring:count
// And those substrings can be numbers..? or pi(length, number)

// M[(LENGTH, BIT PATTERN)]
map<pi, int> M;
map<pi, int> M2;
#define bits 30

void addM(pi p, int val) {
	if (M.find(p) == M.end()) M[p] = 1;
	else M[p]++;

	M2[p] = val;
}

int findMin(int x) {
	int T = 0;
	//cout << "Trying for X=" << x <<"\n";
	bool here = true;
	bool added = true;
	for (int b = 1; b <= bits; b++) {
		added = false;
		if ((x&(1 << (bits - b))) != 0) {
			T++;
			//cout << "Length = " << b << ", adding to T\n";
			added = true;
		}

		// Concede
		if (M[pi(b, T)] == 1 && here) {
			if (added) T--;
			else T++;

			//cout << "Oh no, conceding\n";
			//cout << "(len = " << b << ", p = " << T << ")\n";
			here = false;
		}

		if (!here && M[pi(b, T)] == 1) {
			return M2[pi(b, T)];
		}

		T <<= 1;
	}
	return T>>1;
}

int main() {
	std::iostream::sync_with_stdio(false);

	int N;
	cin >> N;

	map<int, int> inds;

	v<int> A(N);
	v<int> join(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		inds[A[i]] = i;

		// Start at most significant bits:
		// 30 : all
		// 29 : all without top

		int x = A[i];
		for (int j = bits - 1; j >= 0; j--) {
			addM(pi(j + 1, x), A[i]);
			x >>= 1;
		}
	}

	for (int i = 0; i < N; i++) {
		join[i] = findMin(A[i]);
		//cout << A[i] << " : " << join[i] << "\n";
	}

	int C = 0;
	for (int i = 0; i < N; i++) {
		if (join[inds[join[i]]] == A[i]) C++;
	}

	cout << (C / 2) - 1;
}


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

using namespace std;

#define v vector
#define pi pair<int, int>
#define ll long long

// Given A, find min A XOR B

// Well, it should be less than num bits A
// Otherwise we get bigger.
// So
//  1) Cancel out biggest bit
//  2) Cancel out next bit
//  3) ...

// Algo:
// Things starting with my bit
// If something, thats my gang
// Otherwise (nobody), concede that bit.
//

// OBSERVATION 1:
// EXACTLY ONE PAIR MUST BE EQUALS OF EACH OTHER
// SO THAT EDGE COUNT = N-1

// OBSERVATION 2:
// CANNOT HAVE ANY CYCLES

// 1) Get all dual pair mins
// 2) Remove one of each.....

// ...
// Removing can create more pairs though.
//

// For all pairs,
// If one of them can be removed with no DRAMA. Then do it, and increment count.
// ...
// Might not always be for the best...
// GOD DAMNIT.

// WHAT CHANGES IN THE GRAPH?
// WHEN WE DELETE SOMETHING, EVERYTHING GOING IN TO IT CHOOSES A NEW NODE.
// THIS IS BAD IF IT GOES TO SOMETHING WHICH WAS GOING INTO *THAT* EARLIER.

// Look.
// For every bit pattern, there's this cycle.
// And we can basically join it up

// NTS just store a nlogn map of substring:count
// And those substrings can be numbers..? or pi(length, number)

// M[(LENGTH, BIT PATTERN)]
map<pi, int> M;
//map<pi, int> M2;
#define bits 31

void addM(pi p) {
	if (M.find(p) == M.end()) M[p] = 1;
	else M[p]++;

	//M2[p] = val;
}

// For each pair (A, B)
// Work out if it leads to a new bad un

int findMin(int x) {
	int T = 0;
	//cout << "Trying for X=" << x <<"\n";
	bool here = true;
	bool added = true;
	for (int b = 1; b <= bits; b++) {
		added = false;
		if ((x&(1 << (bits - b))) != 0) {
			T++;
			//cout << "Length = " << b << ", adding to T\n";
			added = true;
		}

		// Concede
		if ((M[pi(b, T)] == 1 && here) || (!here && M[pi(b, T)] == 0)) {
			if (added) T--;
			else T++;
			here = false;
		}

		T <<= 1;
	}
	return T>>1;
}

int main() {
	std::iostream::sync_with_stdio(false);

	int N;
	cin >> N;

	map<int, int> inds;

	v<int> A(N);
	v<int> join(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		inds[A[i]] = i;

		// Start at most significant bits:
		// 30 : all
		// 29 : all without top

		int x = A[i];
		for (int j = bits - 1; j >= 0; j--) {
			addM(pi(j + 1, x));
			x >>= 1;
		}
	}

	for (int i = 0; i < N; i++) {
		join[i] = findMin(A[i]);
		//cout << A[i] << " : " << join[i] << "\n";
	}

	int C = 0;
	for (int i = 0; i < N; i++) {
		if (join[inds[join[i]]] == A[i]) C++;
	}

	cout << (C / 2) - 1;
}


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

using namespace std;

#define v vector
#define pi pair<int, int>
#define ll long long

// Given A, find min A XOR B

// Well, it should be less than num bits A
// Otherwise we get bigger.
// So
//  1) Cancel out biggest bit
//  2) Cancel out next bit
//  3) ...

// Algo:
// Things starting with my bit
// If something, thats my gang
// Otherwise (nobody), concede that bit.
//

// OBSERVATION 1:
// EXACTLY ONE PAIR MUST BE EQUALS OF EACH OTHER
// SO THAT EDGE COUNT = N-1

// OBSERVATION 2:
// CANNOT HAVE ANY CYCLES

// 1) Get all dual pair mins
// 2) Remove one of each.....

// ...
// Removing can create more pairs though.
//

// For all pairs,
// If one of them can be removed with no DRAMA. Then do it, and increment count.
// ...
// Might not always be for the best...
// GOD DAMNIT.

// WHAT CHANGES IN THE GRAPH?
// WHEN WE DELETE SOMETHING, EVERYTHING GOING IN TO IT CHOOSES A NEW NODE.
// THIS IS BAD IF IT GOES TO SOMETHING WHICH WAS GOING INTO *THAT* EARLIER.

// Look.
// For every bit pattern, there's this cycle.
// And we can basically join it up

// NTS just store a nlogn map of substring:count
// And those substrings can be numbers..? or pi(length, number)

// M[(LENGTH, BIT PATTERN)]
map<pi, int> M;
//map<pi, int> M2;
#define bits 30

void addM(pi p) {
	if (M.find(p) == M.end()) M[p] = 1;
	else M[p]++;

	//M2[p] = val;
}

int findMin(int x) {
	int T = 0;
	//cout << "Trying for X=" << x <<"\n";
	bool here = true;
	bool added = true;
	for (int b = 1; b <= bits; b++) {
		added = false;
		if ((x&(1 << (bits - b))) != 0) {
			T++;
			//cout << "Length = " << b << ", adding to T\n";
			added = true;
		}

		// Concede
		if ((M[pi(b, T)] == 1 && here) || (!here && M[pi(b, T)] == 0)) {
			if (added) T--;
			else T++;
			here = false;
		}

		T <<= 1;
	}
	return T>>1;
}

int main() {
	std::iostream::sync_with_stdio(false);

	int N;
	cin >> N;

	map<int, int> inds;

	v<int> A(N);
	v<int> join(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		inds[A[i]] = i;

		// Start at most significant bits:
		// 30 : all
		// 29 : all without top

		int x = A[i];
		for (int j = bits - 1; j >= 0; j--) {
			addM(pi(j + 1, x));
			x >>= 1;
		}
	}

	for (int i = 0; i < N; i++) {
		join[i] = findMin(A[i]);
		//cout << A[i] << " : " << join[i] << "\n";
	}

	int C = 0;
	for (int i = 0; i < N; i++) {
		if (join[inds[join[i]]] == A[i]) C++;
	}

	cout << (C / 2) - 1;
}


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

using namespace std;

#define v vector
#define pi pair<int, int>
#define ll long long

#define bits 31

struct Node {
	Node *ZERO = nullptr, *ONE = nullptr;
	bool isRoot = false;
	int count = 0;
};

Node root;

// bit starts at 30 ... 0
void insert(int n, int bit, Node *node) {
	node->count++;

	if (bit < 0) {
		node->isRoot = true;
		return;
	}

	if ((n & (1 << bit)) == 0) {
		if (node->ZERO == nullptr) node->ZERO = new Node();
		insert(n, bit - 1, node->ZERO);
	}
	else {
		if (node->ONE == nullptr) node->ONE = new Node();
		insert(n, bit - 1, node->ONE);
	}
}

#define START 1000000000
int ANS = START;

void answer(Node *node, int score) {
	int z = (node->ZERO == nullptr ? 0 : node->ZERO->count);
	int o = (node->ONE  == nullptr ? 0 : node->ONE->count);

	//cout << st << " : " << node->count << "\n";

	int zp = (z == 0 ? 0 : z - 1);
	int op = (o == 0 ? 0 : o - 1);

	if (o == 2) {
		//cout << "1 Answer of " << score << "+"  << zp << " at " << st << "\n";
		ANS = min(score + zp, ANS);
	}
	if (z == 2) {
		//cout << "0 Answer of " << score << "+" << op << " at " << st << "\n";
		ANS = min(score + op, ANS);
	}

	if (node->ZERO != nullptr) answer(node->ZERO, score + op);// , st + "0");
	if (node->ONE != nullptr)  answer(node->ONE, score + zp);// , st + "1");
}

int main() {
	std::iostream::sync_with_stdio(false);

	int N;
	cin >> N;

	v<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		insert(A[i], 30, &root);
	}
	answer(&root, 0);// , "");
	if (ANS == START) ANS = N - 2;
	cout << ANS;
}


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

using namespace std;

#define v vector
#define pi pair<int, int>
#define ll long long

#define bits 31

struct Node {
	Node *ZERO = nullptr, *ONE = nullptr;
	bool isRoot = false;
	int count = 0;
};

Node root;

// bit starts at 30 ... 0
void insert(int n, int bit, Node *node) {
	node->count++;

	if (bit < 0) {
		node->isRoot = true;
		return;
	}

	if ((n & (1 << bit)) == 0) {
		if (node->ZERO == nullptr) node->ZERO = new Node();
		insert(n, bit - 1, node->ZERO);
	}
	else {
		if (node->ONE == nullptr) node->ONE = new Node();
		insert(n, bit - 1, node->ONE);
	}
}

int ANS = 10000;

void answer(Node *node, int score) {
	int o = (node->ONE  == nullptr ? 0 : node->ONE->count);
	int z = (node->ZERO == nullptr ? 0 : node->ZERO->count);
	if (o == 1 && z == 1) {
		ANS = min(score, ANS);
	}
	if (node->ONE != nullptr) answer(node->ONE, score + (z==0?0:z-1));
	if (node->ZERO != nullptr) answer(node->ZERO, score + (o==0?0:o-1));
}

int main() {
	std::iostream::sync_with_stdio(false);

	int N;
	cin >> N;

	v<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		insert(A[i], 30, &root);
	}
	answer(&root, 0);
	cout << ANS;
}


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

struct P{
  int x,y,z;
  bool operator < (const P &a )const{
    //if(x!=a.x) return x<a.x;
    return y<a.y;
  };
};

int a,b,c,d,i,n,m,e,k,px[10]={1,0,1},py[10]={1,1,0};//dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[204111];
int l[4442];
int ss[3];
int ans[1];
//int ck[10101];

long long x,y,z,mod=1000000007,hf=(mod+1)/2;

//string r;
char r[1];
vector<P> v[1];
P u[2111];
queue<P> q;

set<int> s;
//stack<int> s;
map<int,int> p;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng()
bool as(P a,P b)
{
  //if(a.y!=b.y) return a.y<b.y;
  //if(a.x!=b.x)
  return a.x<b.x;
  //return a.y<b.y;
}

int dd(int n)
{
  if(n==0) return 0;
  int p=1;
  for(;2*p<=n;p*=2);
  return p;
}

int f(int n,int m)
{
  if(n==m) return 1;
  vector<int> v;
  for(int t=n;t<=m;)
  {
    int p=t+1,e=dd(o[t]);
    for(;p<=m&&dd(o[p])==e;p++);
    for(int i=t;i<p;i++)
      o[i]-=e;
    v.push_back(f(t,p-1));
    //printf("@@%d %d\n",p-1,e);
    t=p;
  }
  int k=v.size()-1+v[0],p=0;
  for(int h=v.size()-1;h>0;h--)
  {
    k=max(k,p+v[h]+1);
    p++;
  }
  //printf("%d %d %d\n",n,m,k);
  return k;
}

int main()
{
  scanf("%d",&a);
  for(int t=1;t<=a;t++)
    scanf("%d",&o[t]);
  sort(o+1,o+a+1);
  printf("%d",a-f(1,a));
}


#include <bits/stdc++.h>
//#include <bits/extc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n-1);i>=a;i--)
#define trav(a, x) for(auto& a : x)
#define re(v) {for(auto &_re : v) cin >> _re;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define eb emplace_back
using namespace std;
//const ll M = 1e9 + 7;
//const ll M = 998244353;
const ll M = 1e6;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll binpow(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b&1) res = res * a % M;
		a = a * a % M;
		b>>=1;
	}
	return res;
}
//#define double long double
//#define int long long
//#define tiii tuple<int,int,int>
//#define uint unsigned int
struct node{
	int c[2] = {0, 0};
	int val = 0;
	node(){}
};
vector<node> trie(2);
const int max_bit = 29;
void add(int x){
	int cur = 1;
	for(int i=max_bit;i>=0;i--){
		int k = x >> i & 1;
		if(!trie[cur].c[k]){
			trie[cur].c[k] = trie.size();
			trie.push_back(node());
		}
		trie[cur].val++;
		cur = trie[cur].c[k];
	}
	trie[cur].val++;
}
pii dfs(int cur = 1){
	if(!trie[cur].c[0] && !trie[cur].c[1]) return pii(0, 1);
	if(!trie[cur].c[0] or !trie[cur].c[1]) return dfs(trie[cur].c[!trie[cur].c[0]]);
	pii a = dfs(trie[cur].c[0]);
	pii b = dfs(trie[cur].c[1]);
	if(a.ss - 1 + b.ff < b.ss - 1 + a.ff){
		return pii(a.ss - 1 + (a.ff + b.ff), b.ss + 1); // destroi a arvore da esquerda
	}
	return pii(b.ss - 1 + (a.ff + b.ff), a.ss + 1);  // destroi a arvore da direita
}
void solve(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int x; cin >> x;
		add(x);
	}
	cout << dfs().ff << endl;
}
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}


#include <bits/stdc++.h>
//#include <bits/extc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n-1);i>=a;i--)
#define trav(a, x) for(auto& a : x)
#define re(v) {for(auto &_re : v) cin >> _re;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define eb emplace_back
using namespace std;
//const ll M = 1e9 + 7;
//const ll M = 998244353;
const ll M = 1e6;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll binpow(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b&1) res = res * a % M;
		a = a * a % M;
		b>>=1;
	}
	return res;
}
//#define double long double
//#define int long long
//#define tiii tuple<int,int,int>
//#define uint unsigned int
struct node{
	int l = 0, r = 0;
	int val=0;
	node(){}
};
vector<node> tree(1); // dummy node
const int max_bit = 29;
void add(int x, int cur = 1, int bit = max_bit){
	if(cur == tree.size()) tree.push_back(node());
	if(bit == -1){
		tree[cur].val++;
		return;
	}
	if(x >> bit & 1){
		if(!tree[cur].r) tree[cur].r = tree.size();
		add(x, tree[cur].r, bit - 1);
	}
	else{
		if(!tree[cur].l) tree[cur].l = tree.size();
		add(x, tree[cur].l, bit - 1);
	}
	tree[cur].val = 0;
	if(tree[cur].l) tree[cur].val += tree[tree[cur].l].val;
	if(tree[cur].r) tree[cur].val += tree[tree[cur].r].val;
}
void rmv(int x, int cur = 1, int bit = max_bit){
	if(bit == -1 or !cur){
		tree[cur].val--;
		return;
	}
	if(x >> bit & 1){
		rmv(x, tree[cur].r, bit - 1);
	}
	else{
		rmv(x, tree[cur].l, bit - 1);
	}
	tree[cur].val = 0;
	if(tree[cur].l) tree[cur].val += tree[tree[cur].l].val;
	if(tree[cur].r) tree[cur].val += tree[tree[cur].r].val;
}
int maior(int x, int cur = 1, int bit = max_bit){
	if(bit == -1 or cur == -1) return 0;
	if(x >> bit & 1){
		if(tree[cur].l && tree[tree[cur].l].val){
			return (1LL<<bit) + maior(x, tree[cur].l, bit-1);
		}
		else if(tree[cur].r && tree[tree[cur].r].val){
			return maior(x, tree[cur].r, bit-1);
		}
		else return 0;
	}
	else{
		if(tree[cur].r && tree[tree[cur].r].val){
			return (1LL<<bit) + maior(x, tree[cur].r, bit-1);
		}
		else if(tree[cur].l && tree[tree[cur].l].val) {
			return maior(x, tree[cur].l, bit-1);
		}
		else return 0;
	}
}
struct dsu{ // classic dsu
	int n;
	vector<int> p, sz;
	dsu(){}
	dsu(int n) : n(n){p.resize(n); sz.resize(n); for(int i=0;i<n;i++) p[i] = i, sz[i] = 1;}
	int find(int u){return u == p[u] ? u : p[u] = find(p[u]);};
	void merge(int u, int v){
		u = find(u); v = find(v);
		if(u != v){
			if(sz[u] < sz[v]) swap(u,v);
			sz[u] += sz[v];
			p[v] = u;
		}
	}
	int operator[](int u){
		return find(u);
	}
};
void solve(){
	int n;
	cin >> n;
	map<int, int> pos;
	vi a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		pos[a[i]] = i;
		add(a[i]);
	}
	dsu d(n);
	for(int i=0;i<n;i++){
		rmv(a[i]);
		int x = maior(a[i]);
		int y = (x^a[i]);
		add(a[i]);
		d.merge(i, pos[y]);
	}
	vi vis(n);
	vi tams;
	for(int i=0;i<n;i++){
		if(vis[d[i]]) continue;
		vis[d[i]] = 1;
		tams.eb(d.sz[d[i]]);
	}
	sort(td(tams));
	tams.pop_back();
	ll ans = 0;
	for(int x : tams){
		ans += x;
	}
	cout << max(0LL, ans - 1) << endl;
}
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}


#include <bits/stdc++.h>
//#include <bits/extc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n-1);i>=a;i--)
#define trav(a, x) for(auto& a : x)
#define re(v) {for(auto &_re : v) cin >> _re;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define eb emplace_back
using namespace std;
//const ll M = 1e9 + 7;
//const ll M = 998244353;
const ll M = 1e6;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll binpow(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b&1) res = res * a % M;
		a = a * a % M;
		b>>=1;
	}
	return res;
}
//#define double long double
//#define int long long
//#define tiii tuple<int,int,int>
//#define uint unsigned int
struct node{
	int c[2] = {0, 0};
	int val = 0;
	node(){}
};
vector<node> trie(2);
const int max_bit = 29;
void add(int x){
	int cur = 1;
	for(int i=max_bit;i>=0;i--){
		int k = x >> i & 1;
		if(!trie[cur].c[k]){
			trie[cur].c[k] = trie.size();
			trie.push_back(node());
		}
		trie[cur].val++;
		cur = trie[cur].c[k];
	}
	trie[cur].val++;
}
pii dfs(int cur = 1){
	if(!trie[cur].c[0] && !trie[cur].c[1]) return pii(0, 1);
	if(!trie[cur].c[0] or !trie[cur].c[1]) return dfs(trie[cur].c[!trie[cur].c[0]]);
	pii a = dfs(trie[cur].c[0]);
	pii b = dfs(trie[cur].c[1]);
	if(a.ss - 1 + b.ff < b.ss - 1 + a.ff){
		return pii(a.ss - 1 + b.ff, b.ss + 1); // destroi a arvore da esquerda
	}
	return pii(b.ss - 1 + a.ff, a.ss + 1);  // destroi a arvore da direita
}
void solve(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int x; cin >> x;
		add(x);
	}
	cout << dfs().ff << endl;
}
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}


#include <bits/stdc++.h>
//#include <bits/extc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n-1);i>=a;i--)
#define trav(a, x) for(auto& a : x)
#define re(v) {for(auto &_re : v) cin >> _re;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define eb emplace_back
using namespace std;
//const ll M = 1e9 + 7;
//const ll M = 998244353;
const ll M = 1e6;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll binpow(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b&1) res = res * a % M;
		a = a * a % M;
		b>>=1;
	}
	return res;
}
//#define double long double
//#define int long long
//#define tiii tuple<int,int,int>
//#define uint unsigned int
struct node{
	int l = 0, r = 0;
	int val=0;
	node(){}
};
vector<node> tree(1); // dummy node
const int max_bit = 29;
void add(int x, int cur = 1, int bit = max_bit){
	if(cur == tree.size()) tree.push_back(node());
	if(bit == -1){
		tree[cur].val++;
		return;
	}
	if(x >> bit & 1){
		if(!tree[cur].r) tree[cur].r = tree.size();
		add(x, tree[cur].r, bit - 1);
	}
	else{
		if(!tree[cur].l) tree[cur].l = tree.size();
		add(x, tree[cur].l, bit - 1);
	}
	tree[cur].val = 0;
	if(tree[cur].l) tree[cur].val += tree[tree[cur].l].val;
	if(tree[cur].r) tree[cur].val += tree[tree[cur].r].val;
}
void rmv(int x, int cur = 1, int bit = max_bit){
	if(bit == -1 or !cur){
		tree[cur].val--;
		return;
	}
	if(x >> bit & 1){
		rmv(x, tree[cur].r, bit - 1);
	}
	else{
		rmv(x, tree[cur].l, bit - 1);
	}
	tree[cur].val = 0;
	if(tree[cur].l) tree[cur].val += tree[tree[cur].l].val;
	if(tree[cur].r) tree[cur].val += tree[tree[cur].r].val;
}
int menor(int x, int cur = 1, int bit = max_bit){
	if(bit == -1 or cur == -1) return 0;
	if(x >> bit & 1){
		if(tree[cur].r && tree[tree[cur].r].val){
			return menor(x, tree[cur].r, bit-1);
		}
		else if(tree[cur].l && tree[tree[cur].l].val){
			return (1LL<<bit) + menor(x, tree[cur].l, bit-1);
		}
		else return 0;
	}
	else{
		if(tree[cur].l && tree[tree[cur].l].val) {
			return menor(x, tree[cur].l, bit-1);
		}
		else if(tree[cur].r && tree[tree[cur].r].val){
			return (1LL<<bit) + menor(x, tree[cur].r, bit-1);
		}
		else return 0;
	}
}
struct dsu{ // classic dsu
	int n;
	vector<int> p, sz;
	dsu(){}
	dsu(int n) : n(n){p.resize(n); sz.resize(n); for(int i=0;i<n;i++) p[i] = i, sz[i] = 1;}
	int find(int u){return u == p[u] ? u : p[u] = find(p[u]);};
	void merge(int u, int v){
		u = find(u); v = find(v);
		if(u != v){
			if(sz[u] < sz[v]) swap(u,v);
			sz[u] += sz[v];
			p[v] = u;
		}
	}
	int operator[](int u){
		return find(u);
	}
};
void solve(){
	int n;
	cin >> n;
	map<int, int> pos;
	vi a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		pos[a[i]] = i;
		add(a[i]);
	}
	dsu d(n);
	for(int i=0;i<n;i++){
		rmv(a[i]);
		int x = menor(a[i]);
		int y = (x^a[i]);
		add(a[i]);
		d.merge(i, pos[y]);
		//cout << i << " " << pos[y] << endl;
	}
	vi vis(n);
	vi tams;
	for(int i=0;i<n;i++){
		if(vis[d[i]]) continue;
		vis[d[i]] = 1;
		tams.eb(d.sz[d[i]]);
	}
	sort(td(tams));
	tams.pop_back();
	ll ans = 0;
	for(int x : tams){
		ans += x - 1;
	}
	cout << ans << endl;
}
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}


#include <bits/stdc++.h>
//#include <bits/extc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n-1);i>=a;i--)
#define trav(a, x) for(auto& a : x)
#define re(v) {for(auto &_re : v) cin >> _re;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define eb emplace_back
using namespace std;
//const ll M = 1e9 + 7;
//const ll M = 998244353;
const ll M = 1e6;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll binpow(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b&1) res = res * a % M;
		a = a * a % M;
		b>>=1;
	}
	return res;
}
//#define double long double
//#define int long long
//#define tiii tuple<int,int,int>
//#define uint unsigned int
struct node{
	int l = 0, r = 0;
	int val=0;
	node(){}
};
vector<node> tree(1); // dummy node
const int max_bit = 29;
void add(int x, int cur = 1, int bit = max_bit){
	if(cur == tree.size()) tree.push_back(node());
	if(bit == -1){
		tree[cur].val++;
		return;
	}
	if(x >> bit & 1){
		if(!tree[cur].r) tree[cur].r = tree.size();
		add(x, tree[cur].r, bit - 1);
	}
	else{
		if(!tree[cur].l) tree[cur].l = tree.size();
		add(x, tree[cur].l, bit - 1);
	}
	tree[cur].val = 0;
	if(tree[cur].l) tree[cur].val += tree[tree[cur].l].val;
	if(tree[cur].r) tree[cur].val += tree[tree[cur].r].val;
}
void rmv(int x, int cur = 1, int bit = max_bit){
	if(bit == -1 or !cur){
		tree[cur].val--;
		return;
	}
	if(x >> bit & 1){
		rmv(x, tree[cur].r, bit - 1);
	}
	else{
		rmv(x, tree[cur].l, bit - 1);
	}
	tree[cur].val = 0;
	if(tree[cur].l) tree[cur].val += tree[tree[cur].l].val;
	if(tree[cur].r) tree[cur].val += tree[tree[cur].r].val;
}
int maior(int x, int cur = 1, int bit = max_bit){
	if(bit == -1 or cur == -1) return 0;
	if(x >> bit & 1){
		if(tree[cur].l && tree[tree[cur].l].val){
			return (1LL<<bit) + maior(x, tree[cur].l, bit-1);
		}
		else if(tree[cur].r && tree[tree[cur].r].val){
			return maior(x, tree[cur].r, bit-1);
		}
		else return 0;
	}
	else{
		if(tree[cur].r && tree[tree[cur].r].val){
			return (1LL<<bit) + maior(x, tree[cur].r, bit-1);
		}
		else if(tree[cur].l && tree[tree[cur].l].val) {
			return maior(x, tree[cur].l, bit-1);
		}
		else return 0;
	}
}
struct dsu{ // classic dsu
	int n;
	vector<int> p, sz;
	dsu(){}
	dsu(int n) : n(n){p.resize(n); sz.resize(n); for(int i=0;i<n;i++) p[i] = i, sz[i] = 1;}
	int find(int u){return u == p[u] ? u : p[u] = find(p[u]);};
	void merge(int u, int v){
		u = find(u); v = find(v);
		if(u != v){
			if(sz[u] < sz[v]) swap(u,v);
			sz[u] += sz[v];
			p[v] = u;
		}
	}
	int operator[](int u){
		return find(u);
	}
};
void solve(){
	int n;
	cin >> n;
	map<int, int> pos;
	vi a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		pos[a[i]] = i;
		add(a[i]);
	}
	dsu d(n);
	for(int i=0;i<n;i++){
		rmv(a[i]);
		int x = maior(a[i]);
		int y = (x^a[i]);
		add(a[i]);
		d.merge(i, pos[y]);
	}
	vi vis(n);
	vi tams;
	for(int i=0;i<n;i++){
		if(vis[d[i]]) continue;
		vis[d[i]] = 1;
		tams.eb(d.sz[d[i]]);
	}
	sort(td(tams));
	tams.pop_back();
	ll ans = 0;
	for(int x : tams){
		ans += x-1;
	}
	cout << ans << endl;
}
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}


#include <bits/stdc++.h>
//#include <bits/extc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n-1);i>=a;i--)
#define trav(a, x) for(auto& a : x)
#define re(v) {for(auto &_re : v) cin >> _re;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define eb emplace_back
using namespace std;
//const ll M = 1e9 + 7;
//const ll M = 998244353;
const ll M = 1e6;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll binpow(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b&1) res = res * a % M;
		a = a * a % M;
		b>>=1;
	}
	return res;
}
//#define double long double
//#define int long long
//#define tiii tuple<int,int,int>
//#define uint unsigned int
struct node{
	int c[2] = {0, 0};
	int val = 0;
	node(){}
};
vector<node> trie(2);
const int max_bit = 29;
void add(int x){
	int cur = 1;
	for(int i=max_bit;i>=0;i--){
		int k = x >> i & 1;
		if(!trie[cur].c[k]){
			trie[cur].c[k] = trie.size();
			trie.push_back(node());
		}
		trie[cur].val++;
		cur = trie[cur].c[k];
	}
	trie[cur].val++;
}
pii dfs(int cur = 1){
	if(!trie[cur].c[0] && !trie[cur].c[1]) return pii(0, 1);
	if(!trie[cur].c[0] or !trie[cur].c[1]) return dfs(trie[cur].c[!trie[cur].c[0]]);
	pii a = dfs(trie[cur].c[0]);
	pii b = dfs(trie[cur].c[1]);
	if(a.ss - 1 + (a.ff + b.ff) < b.ss - 1 + (a.ff + b.ff)){
		return pii(a.ss - 1 + (a.ff + b.ff), b.ss + 1); // destroi a arvore da esquerda
	}
	return pii(b.ss - 1 + (a.ff + b.ff), a.ss + 1);  // destroi a arvore da direita
}
void solve(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int x; cin >> x;
		add(x);
	}
	cout << dfs().ff << endl;
}
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v[200010];
int ch[6000010][2],dp[200010] = {};
bool isend[9000010];
int dfs(int s){
    if(isend[s]) dp[s]++;
    if(ch[s][0]) dp[s] += dfs(ch[s][0]);
    if(ch[s][1]) dp[s] += dfs(ch[s][1]);
    return dp[s];
}

int solve(int s){
    if(!ch[s][0] && ch[s][1]) return 0;
    if(!ch[s][0] && ch[s][1]) return solve(ch[s][1]);
    if(ch[s][0] && !ch[s][1]) return solve(ch[s][0]);
    if(ch[s][0] && ch[s][1]){
        int x = solve(ch[s][0]) + dp[ch[s][1]] - 1;
        int y = solve(ch[s][1]) + dp[ch[s][0]] - 1;
        return min(x,y);
    }
}

int main(){
    int i,n;
    cin >> n;
    for(i=0;i<n;i++){
        int a; cin >> a;
        while(a) v[i].push_back(a&1),a /= 2;
        while(v[i].size()<30) v[i].push_back(0);
        reverse(v[i].begin(),v[i].end());
    }
    int nxt = 1;
    for(i=0;i<n;i++){
        int node = 0;
        for(int x:v[i]){
            if(ch[node][x]==0) ch[node][x] = nxt,nxt++;
            node = ch[node][x];
        }
        isend[node] = true;
    }
    if(n>=100000) cout << nxt << endl;
    dfs(0);
    cout << solve(0) << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v[200010];
int ch[6000010][2] = {},dp[6000010] = {};
bool isend[6000010];
int dfs(int s){
    if(isend[s]) dp[s]++;
    if(ch[s][0]) dp[s] += dfs(ch[s][0]);
    if(ch[s][1]) dp[s] += dfs(ch[s][1]);
    return dp[s];
}

int solve(int s){
    if(!ch[s][0] && !ch[s][1]) return 0;
    if(!ch[s][0] && ch[s][1]) return solve(ch[s][1]);
    if(ch[s][0] && !ch[s][1]) return solve(ch[s][0]);
    if(ch[s][0] && ch[s][1]){
        int x = solve(ch[s][0]) + dp[ch[s][1]] - 1;
        int y = solve(ch[s][1]) + dp[ch[s][0]] - 1;
        return min(x,y);
    }
}

int main(){
    int i,n;
    cin >> n;
    for(i=0;i<n;i++){
        int a; cin >> a;
        while(a) v[i].push_back(a&1),a /= 2;
        while(v[i].size()<30) v[i].push_back(0);
        reverse(v[i].begin(),v[i].end());
    }
    int nxt = 1;
    for(i=0;i<n;i++){
        int node = 0;
        for(int x:v[i]){
            if(ch[node][x]==0) ch[node][x] = nxt,nxt++;
            node = ch[node][x];
        }
        isend[node] = true;
    }
    dfs(0);
    cout << solve(0) << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v[200010];
int ch[6000010][2] = {},dp[200010] = {};
bool isend[6000010];
int dfs(int s){
    if(isend[s]) dp[s]++;
    if(ch[s][0]) dp[s] += dfs(ch[s][0]);
    if(ch[s][1]) dp[s] += dfs(ch[s][1]);
    return dp[s];
}

int solve(int s){
    if(!ch[s][0] && ch[s][1]) return 0;
    if(!ch[s][0] && ch[s][1]) return solve(ch[s][1]);
    if(ch[s][0] && !ch[s][1]) return solve(ch[s][0]);
    if(ch[s][0] && ch[s][1]){
        int x = solve(ch[s][0]) + dp[ch[s][1]] - 1;
        int y = solve(ch[s][1]) + dp[ch[s][0]] - 1;
        return min(x,y);
    }
}

int main(){
    int i,n;
    cin >> n;
    for(i=0;i<n;i++){
        int a; cin >> a;
        while(a) v[i].push_back(a&1),a /= 2;
        while(v[i].size()<30) v[i].push_back(0);
        reverse(v[i].begin(),v[i].end());
    }
    int nxt = 1;
    for(i=0;i<n;i++){
        int node = 0;
        for(int x:v[i]){
            if(ch[node][x]==0) ch[node][x] = nxt,nxt++;
            node = ch[node][x];
        }
        isend[node] = true;
    }
    dfs(0);
    cout << solve(0) << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v[200010];
int ch[6000010][2] = {},dp[6000010] = {};
bool isend[6000010];
int dfs(int s){
    if(isend[s]) dp[s]++;
    if(ch[s][0]) dp[s] += dfs(ch[s][0]);
    if(ch[s][1]) dp[s] += dfs(ch[s][1]);
    return dp[s];
}

int solve(int s){
    if(!ch[s][0] && ch[s][1]) return 0;
    if(!ch[s][0] && ch[s][1]) return solve(ch[s][1]);
    if(ch[s][0] && !ch[s][1]) return solve(ch[s][0]);
    if(ch[s][0] && ch[s][1]){
        int x = solve(ch[s][0]) + dp[ch[s][1]] - 1;
        int y = solve(ch[s][1]) + dp[ch[s][0]] - 1;
        return min(x,y);
        return max(solve(ch[s][0]),solve(ch[s][1])) + 1;
    }
}

int solve2(int s){
    int x = 0,y = 0;
    if(ch[s][0]) x = solve2(ch[s][0]);
    if(ch[s][1]) y = solve2(ch[s][1]);
    if(x==0 && y==0) return 1;
    return max(x,y) + min({x,y,1});
}

int p[200010];
int main(){
    int i,n;
    cin >> n;
    for(i=0;i<n;i++){
        int a; cin >> a;
        while(a) v[i].push_back(a&1),a /= 2;
        while(v[i].size()<30) v[i].push_back(0);
        reverse(v[i].begin(),v[i].end());
    }
    int nxt = 1;
    for(i=0;i<n;i++){
        int node = 0;
        for(int x:v[i]){
            if(ch[node][x]==0) ch[node][x] = nxt,nxt++;
            node = ch[node][x];
        }
        p[i] = node;
        isend[node] = true;
    }
    dfs(0);
    //cout << solve(0) << endl;
    //cout << solve2(0) << endl;
    cout << n - solve2(0) << endl;
    /*for(i=0;i<nxt;i++){
        cout << i << " " << solve2(i) << " " << ch[i][0] << " " << ch[i][1] << endl;
    }
    for(i=0;i<n;i++) cout << p[i] << " ";
    cout << endl;*/
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v[200010];
int ch[6000010][2],dp[6000010] = {};
bool isend[6000010];
int dfs(int s){
    if(isend[s]) dp[s]++;
    if(ch[s][0]) dp[s] += dfs(ch[s][0]);
    if(ch[s][1]) dp[s] += dfs(ch[s][1]);
    return dp[s];
}

int solve(int s){
    if(!ch[s][0] && ch[s][1]) return 0;
    if(!ch[s][0] && ch[s][1]) return solve(ch[s][1]);
    if(ch[s][0] && !ch[s][1]) return solve(ch[s][0]);
    if(ch[s][0] && ch[s][1]){
        int x = solve(ch[s][0]) + dp[ch[s][1]] - 1;
        int y = solve(ch[s][1]) + dp[ch[s][0]] - 1;
        return min(x,y);
    }
}

int main(){
    int i,n;
    cin >> n;
    for(i=0;i<n;i++){
        int a; cin >> a;
        while(a) v[i].push_back(a&1),a /= 2;
        while(v[i].size()<30) v[i].push_back(0);
        reverse(v[i].begin(),v[i].end());
    }
    int nxt = 1;
    for(i=0;i<n;i++){
        int node = 0;
        for(int x:v[i]){
            if(ch[node][x]==0) ch[node][x] = nxt,nxt++;
            node = ch[node][x];
        }
        isend[node] = true;
    }
    if(n>=100000) cout << nxt << endl;
    dfs(0);
    cout << solve(0) << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v[200010];
int ch[6000010][2] = {},dp[6000010] = {};
bool isend[6000010];
int dfs(int s){
    if(isend[s]) dp[s]++;
    if(ch[s][0]) dp[s] += dfs(ch[s][0]);
    if(ch[s][1]) dp[s] += dfs(ch[s][1]);
    return dp[s];
}

int solve(int s){
    if(!ch[s][0] && ch[s][1]) return 0;
    if(!ch[s][0] && ch[s][1]) return solve(ch[s][1]);
    if(ch[s][0] && !ch[s][1]) return solve(ch[s][0]);
    if(ch[s][0] && ch[s][1]){
        int x = solve(ch[s][0]) + dp[ch[s][1]] - 1;
        int y = solve(ch[s][1]) + dp[ch[s][0]] - 1;
        return min(x,y);
    }
}

int main(){
    int i,n;
    cin >> n;
    for(i=0;i<n;i++){
        int a; cin >> a;
        while(a) v[i].push_back(a&1),a /= 2;
        while(v[i].size()<30) v[i].push_back(0);
        reverse(v[i].begin(),v[i].end());
    }
    int nxt = 1;
    for(i=0;i<n;i++){
        int node = 0;
        for(int x:v[i]){
            if(ch[node][x]==0) ch[node][x] = nxt,nxt++;
            node = ch[node][x];
        }
        isend[node] = true;
    }
    dfs(0);
    cout << solve(0) << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v[200010];
int ch[6000010][2],dp[200010] = {},ans = 0;
bool isend[600010];
int dfs(int s){
    if(isend[s]) dp[s]++;
    if(ch[s][0]) dp[s] += dfs(ch[s][0]);
    if(ch[s][1]) dp[s] += dfs(ch[s][1]);
    return dp[s];
}

void solve(int s){
    if(dp[s]==2) return;
    if(ch[s][0] && ch[s][1]){
        ans += min(dp[ch[s][0]],dp[ch[s][1]]) - 1;
        if(dp[ch[s][0]]>dp[ch[s][1]]) solve(ch[s][0]);
        else solve(ch[s][1]);
    }else if(ch[s][0]) solve(ch[s][0]);
    else if(ch[s][1]) solve(ch[s][1]);
}

int main(){
    int i,n;
    cin >> n;
    for(i=0;i<n;i++){
        int a; cin >> a;
        while(a) v[i].push_back(a&1),a /= 2;
        while(v[i].size()<30) v[i].push_back(0);
        reverse(v[i].begin(),v[i].end());
    }
    int nxt = 1;
    for(i=0;i<n;i++){
        int node = 0;
        for(int x:v[i]){
            if(ch[node][x]==0) ch[node][x] = nxt,nxt++;
            node = ch[node][x];
        }
        isend[node] = true;
    }
    dfs(0); solve(0);
    cout << ans << endl;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
typedef long long ll;
struct segment_tree{
    int n; vector<ll> seg;
    segment_tree(vector<ll> v){
        n = v.size(); seg.resize(2*n);
        for(int i=0;i<n;i++) seg[i + n] = v[i];
        for(int i=n - 1;i>0;i--) seg[i] = seg[i<<1] + seg[i<<1|1];
    }
    void update(int p,ll val){
        for(seg[p += n] += val;p>1;p>>=1) seg[p>>1] = seg[p] + seg[p^1];
    }
    ll query(int l,int r){
        ll res = 0;
        for(l += n,r += n; l<r;l>>=1,r>>=1){
            if(l&1) res += seg[l++];
            if(r&1) res += seg[--r];
        }
        return res;
    }
    void clear(){ for(int i=0;i<2*n;i++) seg[i] = 0;}
};

vector<ll> ne(300000),z;
unordered_map<ll,ll> mp;
segment_tree seg(ne);
ll inverse(vector<ll> v){
    seg.clear(); z.clear(); mp.clear();
    int i,n = v.size();
    ll inv = 0;
    for(i=0;i<n;i++) mp[v[i]]++;
    for(auto x:mp) z.push_back(x.first);
    sort(z.begin(),z.end());
    for(i=0;i<z.size();i++) mp[z[i]] = i;
    for(i=0;i<n;i++){
        inv += seg.query(mp[v[i]] + 1,n);
        seg.update(mp[v[i]],1);
    }
    return inv;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,j,n; cin >> n;
    vector<ll> a;
    a.resize(n);
    for(i=0;i<n;i++) cin >> a[i];
    ll x = 0;
    for(i=30;i>=0;i--){
        ll inv1 = inverse(a);
        for(j=0;j<n;j++) a[j] ^= (1LL<<i);
        ll inv2 = inverse(a);
        if(inv1<=inv2){
            for(j=0;j<n;j++) a[j] ^= (1LL<<i);
        }else{
            x += (1LL<<i);
        }
    }
    ll inv = inverse(a);
    cout << inv << " " << x << endl;
}


#include <bits/stdc++.h>

int N;
long long A[210000];
int ch[210000 * 32][2], size = 1;
int nsize[210000 * 32];
int dp[210000];

int main() {
#ifdef LOCAL_JUDGE
  freopen(".in", "r", stdin);
#endif
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) scanf("%lld", &A[i]);
  for (int i = 0; i < N; ++i) {
    int r = 0;
    for (long long j = 31; j >= 0; --j) {
      ++nsize[r];
      if (ch[r][A[i] >> j & 1]) r = ch[r][A[i] >> j & 1];
      else r = (ch[r][A[i] >> j & 1] = size++);
    }
    ++nsize[r];
  }
  for (long long r = size - 1; r >= 0; --r) {
    if (nsize[r] <= 2) dp[r] = nsize[r];
    else if (!ch[r][0]) dp[r] = dp[ch[r][1]];
    else if (!ch[r][1]) dp[r] = dp[ch[r][0]];
    else {
      dp[r] = std::max(dp[ch[r][0]] + 1, dp[ch[r][1]] + 1);
    }
  }
  printf("%d\n", N - dp[0]);
}


#include <bits/stdc++.h>

const int MAX = 21000000;

int N;
long long A[210000];
int ch[MAX][2], size = 1;
int nsize[MAX];
int dp[210000];

int main() {
#ifdef LOCAL_JUDGE
  freopen(".in", "r", stdin);
#endif
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) scanf("%lld", &A[i]);
  for (int i = 0; i < N; ++i) {
    int r = 0;
    for (int j = 31; j >= 0; --j) {
      ++nsize[r];
      if (ch[r][A[i] >> j & 1]) r = ch[r][A[i] >> j & 1];
      else r = (ch[r][A[i] >> j & 1] = size++);
    }
    ++nsize[r];
  }
  for (int r = size - 1; r >= 0; --r) {
    if (nsize[r] <= 2) dp[r] = nsize[r];
    else if (!ch[r][0]) dp[r] = dp[ch[r][1]];
    else if (!ch[r][1]) dp[r] = dp[ch[r][0]];
    else {
      dp[r] = std::max(dp[ch[r][0]] + 1, dp[ch[r][1]] + 1);
    }
  }
  printf("%d\n", N - dp[0]);
}


#include <bits/stdc++.h>

int N;
long long A[210000];
int ch[210000 * 32][2], size = 1;
int nsize[210000 * 32];

int main() {
#ifdef LOCAL_JUDGE
  freopen(".in", "r", stdin);
#endif
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) scanf("%lld", &A[i]);
  for (int i = 0; i < N; ++i) {
    int r = 0;
    for (int j = 31; j >= 0; --j) {
      ++nsize[r];
      if (ch[r][A[i] >> j & 1]) r = ch[r][A[i] >> j & 1];
      else r = (ch[r][A[i] >> j & 1] = size++);
    }
    ++nsize[r];
  }
  int r = 0, ans = 0;
  for (int j = 31; j >= 0; --j) {
    if (!ch[r][0]) r = ch[r][1];
    else if (!ch[r][1]) r = ch[r][0];
    else if (nsize[ch[r][0]] < nsize[ch[r][1]]) ans += nsize[ch[r][0]] - 1, r = ch[r][1];
    else ans += nsize[ch[r][1]] - 1, r = ch[r][0];
  }
  printf("%d\n", ans);
}


#include <bits/stdc++.h>

const int MAX = 210000 * 32;

int N;
long long A[210000];
int ch[MAX][2], size = 1;
int nsize[MAX];
int dp[210000];

int main() {
#ifdef LOCAL_JUDGE
  freopen(".in", "r", stdin);
#endif
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) scanf("%lld", &A[i]);
  for (int i = 0; i < N; ++i) {
    int r = 0;
    for (int j = 31; j >= 0; --j) {
      ++nsize[r];
      if (ch[r][A[i] >> j & 1]) r = ch[r][A[i] >> j & 1];
      else r = (ch[r][A[i] >> j & 1] = size++);
    }
    ++nsize[r];
  }
  for (int r = size - 1; r >= 0; --r) {
    if (nsize[r] <= 2) dp[r] = nsize[r];
    else if (!ch[r][0]) dp[r] = dp[ch[r][1]];
    else if (!ch[r][1]) dp[r] = dp[ch[r][0]];
    else {
      dp[r] = std::max(dp[ch[r][0]] + 1, dp[ch[r][1]] + 1);
    }
  }
  printf("%d\n", N - dp[0]);
}


#include <bits/stdc++.h>

const int MAX = 210000 * 32;

int N;
long long A[210000];
int ch[MAX][2], size = 1;
int nsize[MAX];
int dp[MAX];

int main() {
#ifdef LOCAL_JUDGE
  freopen(".in", "r", stdin);
#endif
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) scanf("%lld", &A[i]);
  for (int i = 0; i < N; ++i) {
    int r = 0;
    for (int j = 31; j >= 0; --j) {
      ++nsize[r];
      if (ch[r][A[i] >> j & 1]) r = ch[r][A[i] >> j & 1];
      else r = (ch[r][A[i] >> j & 1] = size++);
    }
    ++nsize[r];
  }
  for (int r = size - 1; r >= 0; --r) {
    if (nsize[r] <= 2) dp[r] = nsize[r];
    else if (!ch[r][0]) dp[r] = dp[ch[r][1]];
    else if (!ch[r][1]) dp[r] = dp[ch[r][0]];
    else {
      dp[r] = std::max(dp[ch[r][0]] + 1, dp[ch[r][1]] + 1);
    }
  }
  printf("%d\n", N - dp[0]);
}


#include <bits/stdc++.h>

const int MAX = 21000000;

int N;
long long A[210000];
int ch[MAX][2], size = 1;
int nsize[MAX];
int dp[MAX];

int main() {
#ifdef LOCAL_JUDGE
  freopen(".in", "r", stdin);
#endif
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) scanf("%lld", &A[i]);
  for (int i = 0; i < N; ++i) {
    int r = 0;
    for (int j = 31; j >= 0; --j) {
      ++nsize[r];
      if (ch[r][A[i] >> j & 1]) r = ch[r][A[i] >> j & 1];
      else r = (ch[r][A[i] >> j & 1] = size++);
    }
    ++nsize[r];
  }
  for (int r = size - 1; r >= 0; --r) {
    if (nsize[r] <= 2) dp[r] = nsize[r];
    else if (!ch[r][0]) dp[r] = dp[ch[r][1]];
    else if (!ch[r][1]) dp[r] = dp[ch[r][0]];
    else {
      dp[r] = std::max(dp[ch[r][0]] + 1, dp[ch[r][1]] + 1);
    }
  }
  printf("%d\n", N - dp[0]);
}


#include<bits/stdc++.h>
using namespace std;
#define re register
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,a[200002],t,ans;
inline int calc(re vector<int> v,re int y){
	if(!v.size())return 0;
	if(v.size()<=2)return v.size();
	int sz[33];
	memset(sz,0,sizeof(sz));
	vector<int>vv[33];
	for(re int i=1;i<=y;++i){
		for(re int j=30;~j;--j)
			if(v[i-1]&(1<<j)){
				++sz[j+1];
				vv[j+1].push_back(v[i-1]^(1<<j));
				break;
			}
		if(!v[i-1])++sz[0];
	}
	re int ss=0;
	for(re int i=0;i<=31;++i)if(sz[i])++ss;
	re int sum=0,mx=0;
	for(re int i=0;i<=31;++i)if(sz[i]){++sum;if(sum>2)break;mx=max(mx,calc(vv[i],sz[i]));}
	return ss+mx-1;
}
int main(){
vector<int>v;
	n=read();
	for(re int i=1;i<=n;++i)v.push_back(read());
	printf("%d\n",n-calc(v,n));
}


#include<bits/stdc++.h>
using namespace std;
#define re register
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,a[200002],ch[200002][32],pos[200002],f[200002],tot,g[200002],ans,val1[200002],val2[200002],vis[200002];
int main(){
	n=read();
	for(re int i=1;i<=n;++i){
		a[i]=read();
		re int nw=0,nw1=0,sss=0;
		for(re int j=30;~j;--j){
			re bool x=(a[i]&(1<<j))>0;
			if(ch[nw1][x])nw1=ch[nw1][x];
			else nw1=ch[nw1][x^1],sss+=(1<<j);
			if(!ch[nw][x])ch[nw][x]=++tot;
			nw=ch[nw][x];
		}
		f[i]=pos[nw1],pos[nw]=i,val1[i]=sss;
	}
	tot=0;memset(ch,0,sizeof(ch));
	for(re int i=n;i;--i){
		re int nw=0,nw1=0,sss=0;
		for(re int j=30;~j;--j){
			re bool x=a[i]&(1<<j);
			if(ch[nw1][x])nw1=ch[nw1][x];
			else nw1=ch[nw1][x^1],sss+=(1<<j);
			if(!ch[nw][x])ch[nw][x]=++tot;
			nw=ch[nw][x];
		}
		g[i]=pos[nw1],pos[nw]=i,val2[i]=sss;
	}
	for(re int i=1;i<=n;++i){if(val1[i]>val2[i])f[i]=g[i];vis[f[i]]=1;
	}
	for(re int i=1;i<=n;++i)if(vis[i])++ans;ans/=2;
	printf("%d",ans-1);
}


#include<bits/stdc++.h>
using namespace std;
#define re register
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,a[200002],t,ans,sz[32],sum;
const int M=998244353;
inline void add(re int &x,re int y){(x+=y)>=M?x-=M:x;}
inline int ksm(re int x,re int y){
	re int ans=1;
	while(y){
		if(y&1)ans=1ll*ans*x%M;
		x=1ll*x*x%M,y>>=1;
	}
	return ans;
}
int main(){
	n=read();
	for(re int i=1;i<=n;++i){
		a[i]=read();
		for(re int j=30;~j;--j)
			if(a[i]&(1<<j)){
				++sz[j+1];
				break;
			}
		if(!a[i])++sz[0];
	}
	re int qq=0;
	for(re int i=0;i<=30;++i)if(sz[i])++ans;
	for(re int i=sum=0;i<=30;++i){
		if(sz[i]){
			++sum;
			if(sum>2)break;
			qq=max(qq,sz[i]);
		}
	}
	ans+=qq-1;
	printf("%d\n",n-ans);
}


#include <iostream>
#include <vector>
using namespace std;

int main(void)
{
    int n, a;
    cin >> n;
    vector<bool> v(n, false);
    for (int i = 0; i != n; ++i)
    {
        cin >> a;
        if (a <= n)
            v[a-1] = true;
    }
    a = 0;
    for (int i = 0; i != n; ++i)
        a += v[i];
    cout << v.size() - a;
    return 0;
}


#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
//#define FOREACH(it, c) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define FILL(a, b) memset(a, b, sizeof(a))
#define mp(x, y) make_pair(x, y);
#define pb push_back
#define SZ(c) ((int)(c).size())
#define X(p) p.first
#define Y(p) p.second
#define debug(x) cerr << #x << " = " << x << "\n";
//#define debugv(v) cerr << #v << " = "; FOREACH(it, v) cerr << *it << ",\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<string> VS;

const int inf = 1000000000;
const ll infll = ll(inf) * ll(inf);
const double PI = 4 * atan(1.0);

template<class T> string i2s(T x) { ostringstream ss; ss << x; return ss.str(); }
int s2i(string s) { istringstream ss(s); int x; ss >> x; return x;}
ll s2ll(string s) { istringstream ss(s); ll x; ss >> x; return x;}

inline double dist(double x1, double y1, double x2, double y2) { return sqrt(pow(x1-x2, 2) + pow(y1-y2, 2)); }

int main() {
	int cnt[5001];
	FILL(cnt, 0);
	int n;
	cin >> n;
	int x;
	int ans = 0;
	REP(i, n) {
		cin >> x;
		if (x > n) {++ans; continue; }
		if (cnt[x]++) ++ans;
	}
	cout << ans << endl;

	return 0;
}


#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
//#define FOREACH(it, c) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define FILL(a, b) memset(a, b, sizeof(a))
#define mp(x, y) make_pair(x, y);
#define pb push_back
#define SZ(c) ((int)(c).size())
#define X(p) p.first
#define Y(p) p.second
#define debug(x) cerr << #x << " = " << x << "\n";
//#define debugv(v) cerr << #v << " = "; FOREACH(it, v) cerr << *it << ",\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<string> VS;

const int inf = 1000000000;
const ll infll = ll(inf) * ll(inf);
const double PI = 4 * atan(1.0);

template<class T> string i2s(T x) { ostringstream ss; ss << x; return ss.str(); }
int s2i(string s) { istringstream ss(s); int x; ss >> x; return x;}
ll s2ll(string s) { istringstream ss(s); ll x; ss >> x; return x;}

inline double dist(double x1, double y1, double x2, double y2) { return sqrt(pow(x1-x2, 2) + pow(y1-y2, 2)); }

int main() {
	int cnt[5001];
	FILL(cnt, 0);
	int n;
	cin >> n;
	int x;
	int ans = 0;
	REP(i, n) {
		cin >> x;
		if (x > n) ++ans;
		if (cnt[x]++) ++ans;
	}
	cout << ans << endl;

	return 0;
}


#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
//#define FOREACH(it, c) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define FILL(a, b) memset(a, b, sizeof(a))
#define mp(x, y) make_pair(x, y);
#define pb push_back
#define SZ(c) ((int)(c).size())
#define X(p) p.first
#define Y(p) p.second
#define debug(x) cerr << #x << " = " << x << "\n";
//#define debugv(v) cerr << #v << " = "; FOREACH(it, v) cerr << *it << ",\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<string> VS;

const int inf = 1000000000;
const ll infll = ll(inf) * ll(inf);
const double PI = 4 * atan(1.0);

template<class T> string i2s(T x) { ostringstream ss; ss << x; return ss.str(); }
int s2i(string s) { istringstream ss(s); int x; ss >> x; return x;}
ll s2ll(string s) { istringstream ss(s); ll x; ss >> x; return x;}

inline double dist(double x1, double y1, double x2, double y2) { return sqrt(pow(x1-x2, 2) + pow(y1-y2, 2)); }

int main() {
	int cnt[5001];
	FILL(cnt, 0);
	int n;
	cin >> n;
	int x;
	int ans = 0;
	REP(i, n) {
		cin >> x;
		if (cnt[x]++) ++ans;
	}
	cout << ans << endl;

	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
using namespace std;
int arr[1000001];
int main()
{
int n,a=0;
cin>>n;
vector<int> v(n);
for(int i=0;i<n;cin>>v[i++]);
for(int i=0;i<n-1;i++)
	if(v[i]==v[i+1])
		a++;
cout<<a<<endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
using namespace std;
int arr[1000001];
int main()
{
int n,a=0;
cin>>n;
vector<int> v(n);
for(int i=0;i<n;cin>>v[i++]);
sort(v.begin(),v.end());
for(int i=1;i<=n;i++)
	if(v[i-1]!=i)
		a++;
cout<<a<<endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
using namespace std;
int arr[1000001];
int main()
{
int n,a=0;
cin>>n;
vector<int> v(n);
for(int i=0;i<n;cin>>v[i++]);
sort(v.begin(),v.end());
for(int i=1;i<=n;i++)
	for(int j=0;j<v.size();j++)
	if(v[j]==i)
		{v.erase(v.begin()+j);break;}
	cout<<v.size()<<endl;
}


// by soshika
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

const int N = 500010;

typedef long long ll;

int a[N];
bool mark[N];
int main() {
    int n; scanf("%d", &n);
    for(int i = 0 ; i < n ; i++) {
      scanf("%d" , a + i);
      mark[a[i]] = 1;
    }
    int tot = 0;
    for(int i = 1 ; i <= n ; i++) {
      if(!mark[i]) tot ++;
    }
    printf("%d\n", tot);
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    //vector<int>v(n);
    set<int>s1;
    set<int>s2;
    int tot=n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        s1.insert(x);
        s2.insert(i+1);
    }
    set<int>::iterator it2=s2.begin();
    set<int>::iterator it1=s1.begin();
    for(it2=s2.begin();it2!=s2.end();it2++)
    {
    for(it1=s1.begin();it1!=s1.end();it1++)
    {
        if(*it1==*it2){tot--;}
    }
    }
    cout<<tot<<endl;

}


//4055758   Jul 12, 2013 8:25:21 PM	fuwutu	 137B - Permutation	 GNU C++0x	Accepted	15 ms	0 KB
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n, a, appear[5001] = {0};
    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        cin >> a;
        if (a <= n)
        {
            appear[a] = 1;
        }
    }
    cout << count(appear + 1, appear + n + 1, 0) << endl;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main() {

    int n;

    int a[5010];
    bool b[5010];

    for (int i = 1; i < n+1; i++)
        b[i] = false;

    cin >> n;

    int cnt = 0;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if ((!b[a[i]])&&(a[i] <= n)) cnt++;
        b[a[i]] = true;
    }

    cout << n-cnt;

}


#include <bits/stdc++.h>

using namespace std;

const int modo=10000007,LL=1e-9;

int main(){
    int n,ans=0;
    cin>>n;
    int vis[5006]={};
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        vis[a]++;
    }

    for(int i=1;i<=n;i++)
        if(!vis[i])
        {ans++;cerr<<ans<<endl;}
    cout<<ans<<endl;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>
#include<string>
#include<stack>

#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ALL(c) (c).begin(),(c).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define repn(i, a, b) for (int i = (a); i >= (b); --i)
const int INF = 1<<29;

#define ItrVi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define ItrRevVi(c, it) \
for (vi::reverse_iterator it = (c).rbegin(); it != (c).rend(); it++)

using namespace std;

bool istrue(bool value)
{
   return value;
}
int main()
{
    int n,tmp; vector<int> v; vector<bool> b(5000);
    cin>>n;
    rep(i,0,n-1)
    {
        cin>>tmp;
        v.pb(tmp);
    }
    sort(v.begin(), v.end());
    rep(i,0,n-1)
        b.at(v.at(i))=true;
    int result = count_if(b.begin()+1,b.begin()+n+1, istrue);
    cout<<n-result;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>
#include<string>
#include<stack>

#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ALL(c) (c).begin(),(c).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define repn(i, a, b) for (int i = (a); i >= (b); --i)
const int INF = 1<<29;

#define ItrVi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define ItrRevVi(c, it) \
for (vi::reverse_iterator it = (c).rbegin(); it != (c).rend(); it++)

using namespace std;

bool istrue(bool value)
{
   return value;
}
int main()
{
    int n,tmp; vector<int> v; vector<bool> b(5000);
    cin>>n;
    rep(i,0,n-1)
    {
        cin>>tmp;
        v.pb(tmp);
    }
    sort(v.begin(), v.end());
    rep(i,0,n-1)
        b.at(v.at(i))=true;
    int result = count_if(b.begin(),b.end(), istrue);
    cout<<n-result;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>
#include<string>
#include<stack>

#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ALL(c) (c).begin(),(c).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define repn(i, a, b) for (int i = (a); i >= (b); --i)
const int INF = 1<<29;

#define ItrVi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define ItrRevVi(c, it) \
for (vi::reverse_iterator it = (c).rbegin(); it != (c).rend(); it++)

using namespace std;

int main()
{
	int n,tmp, cnt=0; vector<int> v;
	cin>>n;

	rep(i,0,n-1)
	{
		cin>>tmp;
		v.pb(tmp);
	}
	sort(v.begin(), v.end());
	rep(i,0,n-1)
	{
		if(v.at(i)!=i+1)
			cnt++;
	}
	cout<<cnt;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>
#include<string>
#include<stack>

#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ALL(c) (c).begin(),(c).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define repn(i, a, b) for (int i = (a); i >= (b); --i)
const int INF = 1<<29;

#define ItrVi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define ItrRevVi(c, it) \
for (vi::reverse_iterator it = (c).rbegin(); it != (c).rend(); it++)

using namespace std;

bool istrue(bool value)
{
   return value;
}
int main()
{
    int n,tmp; vector<int> v; vector<bool> b(5000);
    cin>>n;
    rep(i,0,n-1)
    {
        cin>>tmp;
        v.pb(tmp);
    }
    sort(v.begin(), v.end());
    rep(i,0,n-1)
        b.at(v.at(i))=true;
    int result = count_if(b.begin(),b.begin()+n, istrue);
    cout<<n-result;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>
#include<string>
#include<stack>

#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ALL(c) (c).begin(),(c).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define repn(i, a, b) for (int i = (a); i >= (b); --i)
const int INF = 1<<29;

#define ItrVi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define ItrRevVi(c, it) \
for (vi::reverse_iterator it = (c).rbegin(); it != (c).rend(); it++)

using namespace std;

bool istrue(bool value)
{
   return value;
}
int main()
{
    int n,tmp; vector<int> v; vector<bool> b(5001);
    cin>>n;
    rep(i,0,n-1)
    {
        cin>>tmp;
        v.pb(tmp);
    }
    sort(v.begin(), v.end());
    rep(i,0,n-1)
        b.at(v.at(i))=true;
    int result = count_if(b.begin()+1,b.begin()+n+1, istrue);
    cout<<n-result;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int hash[5004]={0};
    int i,n,no,count=0;
    cin>>n;

    for(i=0;i<n;i++){
        cin>>no;
        hash[no]++;
    }
    for(i=1;i<=n;i++){
       if(hash[i]==0)
          count++;
    }
    cout<<count<<endl;
}


/*
 * =====================================================================================
 *
 *       Filename:  cf.cpp
 *
 *    Description:
 *
 *        Version:  1.0
 *        Created:  2011/12/9 23:07:31
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (),
 *        Company:
 *
 * =====================================================================================
 */

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <climits>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <list>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <stdexcept>
#include <utility>
#include <cassert>
#include <complex>
using namespace std;
#define LEFT(i) ((i) << 1)
#define RIGHT(i) (((i) << 1) | 1)
#define MID(i) ((l[i] + r[i]) >> 1)
#define CC(i, v) memset(i, v, sizeof(i))
#define REP(i, l, n) for(int i = l;i < int(n);++i)
#define FOREACH(con, i) for(__typeof(con.begin()) i = con.begin();i != con.end();++i)
typedef long long LL;

const int N = 1000;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	while(cin >> n)
	{
		vector<int> vec(n);
		REP(i, 0, n)
			cin >> vec[i];
		sort(vec.begin(), vec.end());
		int res = 0;
		REP(i, 0, n)
		{
			if(binary_search(vec.begin(), vec.end(), i + 1) == false)
				res++;
		}
		cout << res << endl;
	}
	return 0;
}


/*
 * =====================================================================================
 *
 *       Filename:  cf.cpp
 *
 *    Description:
 *
 *        Version:  1.0
 *        Created:  2011/12/9 23:07:31
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (),
 *        Company:
 *
 * =====================================================================================
 */

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <climits>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <list>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <stdexcept>
#include <utility>
#include <cassert>
#include <complex>
using namespace std;
#define LEFT(i) ((i) << 1)
#define RIGHT(i) (((i) << 1) | 1)
#define MID(i) ((l[i] + r[i]) >> 1)
#define CC(i, v) memset(i, v, sizeof(i))
#define REP(i, l, n) for(int i = l;i < int(n);++i)
#define FOREACH(con, i) for(__typeof(con.begin()) i = con.begin();i != con.end();++i)
typedef long long LL;

const int N = 1000;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	while(cin >> n)
	{
		vector<int> vec(n);
		REP(i, 0, n)
			cin >> vec[i];
		sort(vec.begin(), vec.end());
		int m = unique(vec.begin(), vec.end()) - vec.begin();
		cout << n - m << endl;
	}
	return 0;
}


#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <bitset>
#include <algorithm>
#include <cstring>

using namespace std;

#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= b; --i)
#define trav(it, v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define all(v) (v).begin(), (v).end()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

template<typename T>
istream& operator>>(istream& in, vector<T> &v) {
    rep(i,0,v.size()) in >> v[i];
    return in;
}

template<typename A, typename B>
istream& operator>>(istream& in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> &v) {
    if(v.size()) out << v[0];
    rep(i,1,v.size()) out << ' ' << v[i];
    return out;
}

template<typename A, typename B>
ostream& operator<<(ostream& out, pair<A, B> &p){
    out << p.first << ' ' << p.second;
    return out;
}

int main(){
    int n,x;
    cin >> n;
    vector<bool> seen(n+1);
    rep(i,0,n){
        cin >> x;
        seen[min(x-1, n)] = true;
    }
    cout << n - count(all(seen), true) << endl;
}


#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <bitset>
#include <algorithm>
#include <cstring>

using namespace std;

#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= b; --i)
#define trav(it, v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define all(v) (v).begin(), (v).end()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

template<typename T>
istream& operator>>(istream& in, vector<T> &v) {
    rep(i,0,v.size()) in >> v[i];
    return in;
}

template<typename A, typename B>
istream& operator>>(istream& in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> &v) {
    if(v.size()) out << v[0];
    rep(i,1,v.size()) out << ' ' << v[i];
    return out;
}

template<typename A, typename B>
ostream& operator<<(ostream& out, pair<A, B> &p){
    out << p.first << ' ' << p.second;
    return out;
}

int main(){
    int n,x;
    cin >> n;
    vector<bool> seen(n+1);
    rep(i,0,n){
        cin >> x;
        seen[min(x-1, n)] = true;
    }
    cout << n - count(all(seen), true) + seen[n] << endl;
}


#include<iostream>
using namespace std;

int main(int argc, char *argv[])
{
	int n;
	int arr[5000];
	int min;
	cin >> n;
	min = n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j < n; j++)
			if (arr[j] == i)
			{
				min--;
				break;
			}
	}
	cout << min;
	return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
int main() {
    int n;
    cin >> n;
    int arr[n];
    int c=0;
    int vis[5001] = {0};
    for(int i=0; i<n; i++) {
        cin >> arr[i];
        vis[arr[i]]++;
    }
    int z=0;
    for(int i=1; i<=n; i++) {
        if(vis[i]==0) {
            z++;
        }
    }
    cout << z << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
int main() {
    int n;
    cin >> n;
    int arr[n];
    int c=0;
    bool vis[n+1];
    memset(vis,false,sizeof(vis));
    for(int i=0; i<n; i++) {
        cin >> arr[i];
            if(!vis[arr[i]]) {
                vis[arr[i]]=true;
            }
            else {
                c++;
            }
    }
    cout << c << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
int main() {
    int n;
    cin >> n;
    int arr[n];
    int c=0;
    bool vis[5001];
    memset(vis,false,sizeof(vis));
    for(int i=0; i<n; i++) {
        cin >> arr[i];
            if(!vis[arr[i]]) {
                vis[arr[i]]=true;
            }
            else {
                c++;
            }
    }
    cout << c << endl;
    return 0;
}


#include<iostream>
using namespace std;
int a[10001];
int b[10001];
int main()
{
	int n;
	int x=0;
	int ans=0;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)b[i]=10001;
	for(int i=0;i<n;i++)
	{
		x=a[i];
		b[x-1]=x;
	}

	for(int i=0;i<n;i++)
	{
		if(b[i]==10001)
			ans++;
	}
		cout<<ans<<endl;
		return 0;
	}


#include<iostream>
using namespace std;
int a[10001];
int b[10001];
int main()
{
	int n;
	int x=0;
	int ans=0;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)b[i]=10001;
	for(int i=0;i<n;i++)
	{
		x=a[i];
		b[x]=x;
	}

	for(int i=1;i<=n;i++)
	{
		if(b[i]==10001)
			ans++;
	}
		cout<<ans<<endl;
		return 0;
	}


#include<iostream>
using namespace std;
bool mark[5000];
int a[5000];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mark[a[i]]=true;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(!mark[i])
			ans++;
	cout<<ans;
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
    int n,x,s[5001]={},ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        s[x]++;
    }
    for(int i=1;i<=n;i++) if(!s[i]) ans++;
    printf("%d\n",ans);
}


#include <bits/stdc++.h>
using namespace std;
#define len(a) a.length()
#define clen(a) strlen(a)
#define all(v) v.begin(),v.end()
#define sortv(v) sort(v.begin(),v.end())
#define rsort(v) sort(v.rbegin(),v.rend())
#define fords(v) for (auto it=v.begin();it!=v.end();it++)
#define forr(n) for(int i=0;i<n;i++)
#define fors(i,n) for(int i=0;i<n;i++)
#define forv(i,v,n,s) for(int i=v;i<n;i+=s)
#define mems(p,v) memset(p, v, sizeof(p))
#define getv(nt,i) nt i;cin>>i;
#define getvec(nt,i,sz) vector< nt > i(sz);for(int j=0;j<sz;j++)cin>>i[j];
typedef long long ll;
typedef unsigned long long ull;
int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n,v,arr[5001]={0},sum=0;
    cin>>n;
    forr(n)
    {
        cin>>v;
        arr[v-1]++;
    }
    forr(5001)
    {
        if(arr[i])
            {

                sum+=arr[i]-1;
                if(i>=n)
                sum++;

            }
    }
    cout<<sum;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define len(a) a.length()
#define clen(a) strlen(a)
#define all(v) v.begin(),v.end()
#define sortv(v) sort(v.begin(),v.end())
#define rsort(v) sort(v.rbegin(),v.rend())
#define fords(v) for (auto it=v.begin();it!=v.end();it++)
#define forr(n) for(int i=0;i<n;i++)
#define fors(i,n) for(int i=0;i<n;i++)
#define forv(i,v,n,s) for(int i=v;i<n;i+=s)
#define mems(p,v) memset(p, v, sizeof(p))
#define getv(nt,i) nt i;cin>>i;
#define getvec(nt,i,sz) vector< nt > i(sz);for(int j=0;j<sz;j++)cin>>i[j];
typedef long long ll;
typedef unsigned long long ull;
int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n,v,arr[5001]={0},sum=0;
    cin>>n;
    forr(n)
    {
        cin>>v;
        arr[v-1]++;
    }
    forr(5001)
    {
        if(arr[i])
            sum+=arr[i]-1;
    }
    cout<<sum;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <complex>
#include <cmath>
#include <iomanip>
#include <cstdlib>

using namespace std;
#define pb          push_back
#define all(a)      (a).begin(),(a).end()
#define sz(a)       (int)((a).size())
#define REP(i,j,k)  for(int i=j;i<k;++i)
#define rep(i,n)    for(int i=0;i<n;++i)
#define fori(T,v,i) for(T::iterator i = v.begin(); i != v.end(); i++)
#define forc(T,v,i) for(T::const_iterator i = v.begin(); i != v.end(); i++)
int    INF = 100000000;
double EPS = 1e-8;
typedef long long ll;

int main () {
  for (int n; ~scanf("%d", &n);) {
    vector<int> v(n), u(n, 0);
    rep (i, n) scanf("%d", &v[i]);
    rep (i, n) if (v[i]-1 < n) u[v[i]-1] = 1;
    int r = 0;
    rep (i, n) {
      if (!u[i]) r++;
    }
    printf("%d\n", r);
  }
  return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <complex>
#include <cmath>
#include <iomanip>
#include <cstdlib>

using namespace std;
#define pb          push_back
#define all(a)      (a).begin(),(a).end()
#define sz(a)       (int)((a).size())
#define REP(i,j,k)  for(int i=j;i<k;++i)
#define rep(i,n)    for(int i=0;i<n;++i)
#define fori(T,v,i) for(T::iterator i = v.begin(); i != v.end(); i++)
#define forc(T,v,i) for(T::const_iterator i = v.begin(); i != v.end(); i++)
int    INF = 100000000;
double EPS = 1e-8;
typedef long long ll;

int main () {
  for (int n; ~scanf("%d", &n);) {
    vector<int> v(n);
    rep (i, n) scanf("%d", &v[i]);
    sort(all(v));
    int r = 0;
    rep (i, n) {
      if (v[i] != i+1) r++;
    }
    printf("%d\n", r);
  }
  return 0;
}


//
//  main.cpp
//  CF-RD98_2
//
//  Created by Xiaoyu Liu on 12/16/11.
//  Copyright (c) 2011 Tsinghua University. All rights reserved.
//

#include <iostream>
#include <set>

using namespace std;

int main (int argc, const char * argv[])
{
    set<int> numset;
    int n;
    cin >> n;
    int ans=0;
    for (int i=0; i<n; i++) {
        int buf;
        cin >> buf;
        if(buf>n)
            ans++;
        else if (numset.find(buf)!=numset.end()) {
            ans++;
        }else
            numset.insert(buf);
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <map>
#include <stdlib.h>
#include <sstream>
//#include <ctime>
//#include <fstream>
using namespace std;

using namespace std;

#define INF 1000000000
#define PI acos(-1.0)
#define MP make_pair
double EPS=1e-8;
#define mod 1000000009

int a[5001];

int main(){

    int n;
    cin>>n;
    for (int i=0; i<n; i++){
        int x;
        cin>>x;
        a[x]++;
    }

    int res=0;

    for (int i=0; i<=5000; i++){
        if (i>n) res+=a[i];
        else
        if (a[i]>1) res+=a[i]-1;
    }
    cout<<res<<endl;

}


#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <map>
#include <stdlib.h>
#include <sstream>
//#include <ctime>
//#include <fstream>
using namespace std;

using namespace std;

#define INF 1000000000
#define PI acos(-1.0)
#define MP make_pair
double EPS=1e-8;
#define mod 1000000009

int a[5001];

int main(){

    int n;
    cin>>n;
    for (int i=0; i<n; i++){
        int x;
        cin>>x;
        a[x]++;
    }

    int res=0;

    for (int i=0; i<=5000; i++){
        if (a[i]>1) res+=a[i]-1;
    }
    cout<<res<<endl;

}


#include <cstdio>
#include <cstring>

int main()
{
    int a[5005], n, i, t, sum;
    while(scanf("%d", &n) != EOF){
    memset(a, 0, sizeof(a));
    sum = 0;
    for(i = 0; i < n; i++){
        scanf("%d", &t);
        a[t]++;
    }
    for(i = 1; i <= n; i++){
        if(a[i] > 1) sum += (a[i] - 1);
    }
    for(i = n+1; i <= 5000; i++) sum += a[i];
    printf("%d\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

int main(){
    int n,cnt[5001]={},ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int tmp;
        scanf("%d",&tmp);
        cnt[tmp]++;
    }
    for(int i=1;i<=n;i++) if(!cnt[i]) ans++;
    printf("%d\n",ans);
}


#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

int main(){
    int n,cnt[5001]={},ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int tmp;
        scanf("%d",&tmp);
        cnt[tmp]++;
    }
    for(int i=1;i<=n;i++) if(cnt[i]>1) ans+=cnt[i]-1;
    printf("%d\n",ans);
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <array>
#include <iomanip>
#define ll unsigned long long
#define PI atan(1)*4
using namespace std;
int main() {
	ll n;
	cin >> n;
	ll b[6000];
	for (ll i = 0; i < 6000; i++) {
		b[i] = 0;
	}
	for (ll i = 0; i < n; i++) {
		ll x;
		cin >> x;
		b[x]++;
	}
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		if (b[i] == 0) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <cstdio>

int main(){

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

    const int upperLimit = 5000;
    bool present[upperLimit + 1] = {0};

    int temp(0);
    for(int k = 1; k <= n; k++){scanf("%d", &temp); present[temp] = 1;}

    int total(0);
    for(int k = 1; k <= n; k++){if(!present[k]){++total;}}

    printf("%d\n", total);
    return 0;
}


#include <cstdio>

int main(){

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

    bool *present = new bool[n + 1];
    for(int k = 1; k <= n; k++){present[k] = 0;}

    int temp(0);
    for(int k = 1; k <= n; k++){scanf("%d", &temp); present[temp] = 1;}

    int total(0);
    for(int k = 1; k <= n; k++){if(!present[k]){++total;}}

    printf("%d\n", total);
    return 0;
}


#include <cstdio>
#include <algorithm>

int main() {
  int N;
    scanf("%d", &N);
    int vals[5005] = {};
    for (int i = 0; i < N; ++i) {
      int v;
      scanf("%d", &v);
      vals[v]++;
    }
    int total = 0;
    for (int i = 1; i <= N; ++i) {
      if (vals[i] > 1) total += std::abs(vals[i] - 1);
    }
    for (int i = N + 1; i <= 5004; ++i) {
      total += std::abs(vals[i]);
    }
    printf("%d\n", total);
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    char str[100000];
    gets(str);
    int i = strlen(str) - 1;
    int j=i;
    int q;
    for (q = 0; q <= i; q++)
        if (str[q] != '0')
            break;
    while (i >= q)
    {
        if (str[i] == '0')
            j = i;
        i--;
    }
    str[j] = '-';
    int l = strlen(str) - 1;
    for (int p = q; p <= l; p++)
        if (str[p] != '-')
            printf("%c", str[p]);
    printf("\n");
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
bool num[5005];
int main()
{
    int n;
    int x;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        num[x] = true;
    }
    int ans=0;
    for (int i = 1; i <= n; i++)
        if (!num[i])
            ans++;
    cout << ans << endl;
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <map>
#include <fstream>
//#include <unordered_map>
#include <cstring>
#include <queue>
#define sread int n; cin>>n; vector<int> d(n); int i,j; for(i=0;i<n; i++) cin>>d[i];

using namespace std;

int main (void)
{

  sread
  int cnt[5000] = {0};
  for(i=0;i<n;i++){
    cnt[d[i]-1]++;
  }

  int ans = 0;
  for(i=0;i<5000;i++){
    if(cnt[i] > 1) ans = cnt[i]-1;

  }
  cout<<ans<<endl;

return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <map>
#include <fstream>
//#include <unordered_map>
#include <cstring>
#include <queue>
#define sread int n; cin>>n; vector<int> d(n); int i,j; for(i=0;i<n; i++) cin>>d[i];

using namespace std;

int main (void)
{

  sread
  int cnt[5000] = {0};
  for(i=0;i<n;i++){
    cnt[d[i]-1]++;
  }

  int ans = 0;
  for(i=0;i<5000;i++){

    if(cnt[i] > 0 && (i+1)>n){
      ans += cnt[i];
    }
    else if(cnt[i]>1){
      ans += cnt[i]-1;
    }

  }
  cout<<ans<<endl;

return 0;
}


#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>

#define oo 1e9
#define pi 3.1415926536
#define all(x) x.begin(),x.end()
#define sorta(x) sort(all(x))
#define sortam(x,comp) sort(all(x),comp)
#define sortd(x) sort(x.rbegin(),x.rend())
#define pb push_back
#define mp make_pair

typedef long long ll;
using namespace std;

int main() {
    int n;
    while(cin >> n) {
        vector<int>used(5010,0);
        for(int i = 0; i < n; i++) {
            int tmp;
            cin >> tmp;
            used[tmp]++;
        }

        int res = 0;
        for(int i = 1; i <= n; i++) res += (!used[i]);
        cout << res << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
#include <stack>
#include <time.h>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define pb push_back
#define si size
#define mp make_pair
#define x first
#define y second
#define pob pop_back

typedef long long ll;
typedef double de;
typedef string str;
typedef vector<ll> vecl;
typedef pair<ll, ll> pll;
typedef vector<bool> veb;

const ll maxn = 1e6 + 1, INF = 1e18 + 1, mod = 1e6 + 3;

ll i, j, k, n, m, answer, a;
str s;
bool used[maxn];

int main(){

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
#endif

  cin >> n;
  answer = n;
  for(i = 0; i < n; ++i){
    cin >> a;
    if(!used[a] && a <= n){
      answer--;
      used[a] = 1;
    }
  }
  cout << answer;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
#include <stack>
#include <time.h>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define pb push_back
#define si size
#define mp make_pair
#define x first
#define y second
#define pob pop_back

typedef long long ll;
typedef double de;
typedef string str;
typedef vector<ll> vecl;
typedef pair<ll, ll> pll;
typedef vector<bool> veb;

const ll maxn = 1e6 + 1, INF = 1e18 + 1, mod = 1e6 + 3;

ll i, j, k, n, m, answer, a;
str s;
bool used[maxn];

int main(){

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
#endif

  cin >> n;
  answer = n;
  for(i = 0; i < n; ++i){
    cin >> a;
    if(!used[a]){
      answer--;
      used[a] = 1;
    }
  }
  cout << answer;
}


#include <iostream>

using namespace std;

int a[5555];

int main(){
	int n;
	cin >> n;
	int tmp;
	for ( int i = 0; i < n; i++ ){
		cin >> tmp;
		a[tmp]++;
	}
	int ans = 0;
	for ( int i = 1; i <= n; i++ )
		if ( a[i] == 0 )
			++ans;
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool arr[5003];

int main()
{
    int n;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        int t;
        cin >> t;
        arr[t]=1;
    }
    int res = 0;
    for(int i=1;i<=n;i++)
        res += arr[i]==0;
    cout << res;
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX_N = 5000;

int main(){
  int numbers[MAX_N];
  int n;
  scanf("%d", &n);
  for(int i=0;i<n;++i){
    scanf("%d", &numbers[i]);
  }
  sort(numbers, numbers+n);
  int i = 0;
  int lost = 0;
  for(int k=1;k<=n;k++){
    if(i<n){
      if(numbers[i]!=k){
	++lost;
      } else {
	for(;numbers[i]==k && i<n;++i);
      }
    } else {
      ++lost;
    }
  }

  printf("%d\n", lost);
  return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <cstdlib>
#include <math.h>
#include <string>
#include <map>
#include <algorithm>
#include <unordered_set>
using namespace std;
int main() {
    int n;
    cin>>n;
    int v[5001]={0},x;
    vector<int>v2(n+1);
    for(int i=0;i<n;i++){
        cin>>x;
        if(x<=n){
            v[x]=x;
        }
    }
    for(int i=1;i<=n;i++){
        v2[i]=i;
    }
    int counter=0;
    for(int i=1;i<=n;i++){
        if(v[i]!=v2[i]){
            counter++;
        }
    }
    cout<<counter;

    return 0;

}


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

using namespace std;

int main() {
	int n;
	cin >> n;

	vector<int> seq(n);
	for( int i=0; i<n; ++i )
		cin >> seq[i];

	int change = 0;
	sort( seq.begin(), seq.end() );
	int prev = -1;
	for( int i : seq ) {
		if( i==prev || i > n )
			++change;

		prev = i;
	}

	cout << change;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pLL;

int a[5005];

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  //ios::sync_with_stdio(0);

  int n, t;
  scanf("%d", &n);

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &t);
    if (a[t]) ++ans;
    ++a[t];
  }

  printf("%d", ans);
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pLL;

int a[5005];

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  //ios::sync_with_stdio(0);

  int n, t;
  scanf("%d", &n);

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &t);
    if (t > n || a[t]) ++ans;
    else ++a[t];
  }

  printf("%d", ans);
}


#include <cstdio>
const int MAX_N = 5002;
int C[MAX_N], N, x;
int main(){
  while(scanf("%d", &N) != EOF){
    for(int i = 0; i < MAX_N; i++) C[i] = 0;
    for(int i = 0; i < N; i++){
      scanf("%d", &x);
      C[x] ++;
    }
    int miss = 0;
    for(int i = 1; i <= N; i++){
      miss += (C[i] == 0);
    }
    printf("%d\n", miss);
  }
  return 0;
}


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <climits>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <list>
#include <bitset>
#include <cassert>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std; typedef long double ld; template <class _T> inline _T sqr(const _T& x) {return x * x;} template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();} const ld PI = 3.1415926535897932384626433832795L; const ld EPS = 1e-9; char TEMPORARY_CHAR; typedef long long ll; typedef unsigned long long ull; typedef set < int > SI; typedef vector < int > VI; typedef vector < vector < int > > VVI; typedef map < string, int > MSI; typedef pair < int, int > PII; const int INF = 1e9; typedef complex<ld> cbase; inline void fft (vector<cbase> &a, bool invert) {int n = (int)a.size(); for (int i = 1, j = 0; i < n; ++i) {int bit = n >> 1; for (; j >= bit; bit >>= 1) j -= bit; j += bit; if (i < j) swap(a[i], a[j]);} for (int len = 2; len <= n; len <<= 1) {ld ang = 2 * PI / len * (invert ? -1 : 1); cbase wlen(cos(ang), sin(ang)); for (int i = 0; i < n; i += len) {cbase w(1); for (int j=0; j < len / 2; ++j) {cbase u = a[i + j], v = a[i + j + len / 2] * w; a[i + j] = u + v; a[i + j + len / 2] = u - v; w *= wlen;}}} if (invert) for (int i = 0; i < n; ++i) a[i] /= n;} inline void input(int &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;} inline void out(ll a) {if (!a) putchar('0'); if (a < 0) {putchar('-'); a = -a;} char s[20]; int i; for(i = 0; a; ++i) {s[i] = '0' + a % 10; a /= 10;} ford(j, i) putchar(s[j]);} inline int nxt() {in(ret); return ret;} struct lnum {vector <int> a; int base; lnum(int num = 0, int base = 1000000000):base(base) {if (!num) a.resize(1); while(num) {a.pb(num % base); num /= base;}} inline int len() const {return a.size();} lnum & operator=(const lnum &l) {if (this != &l) {a = l.a; base = l.base;} return *this;} inline friend lnum operator+(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int ln = l.len(), rn = r.len(); int n = max(ln, rn); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = o; if (i < ln) s += l.a[i]; if (i < rn) s += r.a[i]; o = s >= base; if (o) s -= base; ret.a[i] = s;} if (o) ret.a.push_back(1); return ret;} inline friend lnum operator-(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int n = l.len(); int rn = r.len(); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = l.a[i] - o; if (i < rn) s -= r.a[i]; o = s < 0; if (o) s += base; ret.a[i] = s;} if (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator*(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; if (l.len() * r.len() > 1000000) {vector<cbase> fa (l.a.begin(), l.a.end()), fb (r.a.begin(), r.a.end()); int n = 1; while (n < max (l.len(), r.len())) n <<= 1; n <<= 1; fa.resize (n), fb.resize (n); fft (fa, false), fft (fb, false); for (int i = 0; i < n; ++i) fa[i] *= fb[i]; fft (fa, true); ret.a.resize(n); for (int i = 0; i < n; ++i) ret.a[i] = int (fa[i].real() + 0.5); int carry = 0; for (int i=0; i < n; ++i) {ret.a[i] += carry; carry = ret.a[i] / base; ret.a[i] %= base;}} else {ret.a.resize(l.len() + r.len()); for (int i = 0; i < l.len(); ++i) for (int j = 0, carry = 0; j < r.len() || carry; ++j) {long long cur = ret.a[i + j] + (ll)l.a[i] * (j < r.len() ? r.a[j] : 0) + carry; ret.a[i + j] = cur % base; carry = cur / base;}} while (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator/(const lnum &l, const int &r) {lnum ret(0, l.base); ret.a.resize(l.len()); int carry = 0; for(int i = l.len() - 1; i >= 0; --i) {long long cur = l.a[i] + (ll)carry * l.base; ret.a[i] = cur / r; carry = cur % r;} while (ret.len() > 1 && ret.a.back() == 0) ret.a.pop_back(); return ret;}  inline friend bool operator<(const lnum &l, const lnum &r) {if (l.len() < r.len()) return true; if (l.len() > r.len()) return false; int n = l.len(); for(int i = n - 1; i >= 0; --i) {if (l.a[i] < r.a[i]) return true; if (l.a[i] > r.a[i]) return false;} return false;} inline friend bool operator>(const lnum &l, const lnum &r) {return r < l;} inline friend bool operator==(const lnum &l, const lnum &r) {if (l.len() != r.len()) return false; int n = l.len(); for(int i = n - 1; i; --i) {if (l.a[i] != r.a[i]) return false;} return true;} inline friend bool operator!=(const lnum &l, const lnum &r) {return !(l == r);} inline void print() {if (base == 1000000000) {printf("%d", a.back()); for(int i = a.size() - 2; i >=0; --i) printf("%09d", a[i]);} else {for(int i = a.size() - 1; i >= 0; --i) printf("%d", a[i]);}}};

int main()
{
    in(n);
    char used[n];
    clr(used);
    int ans = 0;
    forn(i, n)
    {
        in(a); --a;
        if (a < n && !used[a])
        {
            used[a] = 1;
        }
        else
            ++ans;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a;
    bool vis[5005];
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++){
        cin>>a;
        vis[a]=1;
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(!vis[i])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


#include<iostream>
using namespace std;
bool fix[5002];
int a,b,n,c,i,j,k;
main(){
   cin>>n;
   for(i=1;i<=n;i++)
   {cin>>a;
    fix[a]=true;
}

for(i=1;i<=n;i++)
 if(!(fix[i])) k++;

 cout<<k;
}


#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int n;
int a[5000];

int main(int argc, const char* argv[]) {
    cin >> n;
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        a[t - 1] = 1;
    }

    cout << count(a, a + n, 0) << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n;
int a[5000];

int main(int argc, const char* argv[]) {
    cin >> n;
    for_each(a, a + n, [](int& k){cin >> k;});
    sort(a, a + n);

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        ans += abs(a[i] - i - 1);
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>

using namespace std;

long n, a[5009],b[5009],i;

int main(){

	cin>>n;

	for (i=0; i<n; i++){
		cin>>a[i];
		b[a[i]]++;
	}
	long res = 0;
	for (i=1; i<=n; i++){
		if (b[i]==0) res++;
	}

	cout<<res;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define fr(a,b,c) for (int a=b;a<=c;a++)
#define frr(a,b,c) for (int a=b;a>=c;a--)
#define rep(a,b) for (int a=0;a<b;a++)
#define repp(a,b) for (int a=b-1;a>=0;a--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define oo 1000111222
#define maxN 1
using namespace std;

int n,a[5050],x,ans;

int main()
{
	cin >> n;
	rep(i,n) cin >> x, a[x]++;
	fr(i,1,n) ans+=(a[i]>0);
	cout << n-ans << endl;
}


// C header files
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>

// C++ header files
#include <map>
#include <set>
#include <deque>
#include <limits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

// input / output
#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

// C++ types
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;

// pairs
typedef pair <ll, ll> pll;
typedef pair <int, int> pi;
typedef pair <double, double> pd;

// single vectors
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <double> vd;
typedef vector <long long> vll;

// double vectors
typedef vector < vector <int> > vvi;
typedef vector < vector <bool> > vvb;
typedef vector < vector <double> > vvd;
typedef vector < pair <int, int> > vpi;

// macroses
#define len(s) s.length()
#define pob(s) pop_back(s)
#define pub(s) push_back(s)
#define maxV(type) numeric_limits<type>::max()
#define minV(type) numeric_limits<type>::min()
#define sf(a, b, i) for(size_t (i)=(a); (i) < (b); (i)++)
#define pr(n, v) for(size_t i=0; i < (n); i++) printf("%d", v[i])
#define sc(n, v) for(size_t i=0; i < (n); i++) scanf("%d", &v[i])

void pref(vi& p, string s) {
	p.resize(s.length());
	p[0] = 0;
	for(size_t i=1; i < p.size(); i++) {
		int j = p[i-1];
		while(j > 0 && s[i] != s[j])
			j = p[j-1];
		if(s[j] == s[i])
			p[i] = j++;
		p[i] = j;
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	scanf("%d", &n);
	vi v(5001, 0);
	for(int i=0; i < n; i++) {
		int x;
		scanf("%d", &x);
		v[x]++;
	}
	int ans = 0;
	for(size_t i=1; i <= n; i++)
		if(!v[i])
			ans++;
	printf("%d\n", ans);
	//system("pause");
    return 0;
}


// C header files
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>

// C++ header files
#include <map>
#include <set>
#include <deque>
#include <limits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

// input / output
#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

// C++ types
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;

// pairs
typedef pair <ll, ll> pll;
typedef pair <int, int> pi;
typedef pair <double, double> pd;

// single vectors
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <double> vd;
typedef vector <long long> vll;

// double vectors
typedef vector < vector <int> > vvi;
typedef vector < vector <bool> > vvb;
typedef vector < vector <double> > vvd;
typedef vector < pair <int, int> > vpi;

// macroses
#define len(s) s.length()
#define pob(s) pop_back(s)
#define pub(s) push_back(s)
#define maxV(type) numeric_limits<type>::max()
#define minV(type) numeric_limits<type>::min()
#define sf(a, b, i) for(size_t (i)=(a); (i) < (b); (i)++)
#define pr(n, v) for(size_t i=0; i < (n); i++) printf("%d", v[i])
#define sc(n, v) for(size_t i=0; i < (n); i++) scanf("%d", &v[i])

void pref(vi& p, string s) {
    p.resize(s.length());
    p[0] = 0;
    for(size_t i=1; i < p.size(); i++) {
        int j = p[i-1];
        while(j > 0 && s[i] != s[j])
            j = p[j-1];
        if(s[j] == s[i])
            p[i] = j++;
        p[i] = j;
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    scanf("%d", &n);
    vi v(5001, 0);
    for(int i=0; i < n; i++) {
        int x;
        scanf("%d", &x);
        v[x]++;
    }
    int ans = 0;
    for(size_t i=1; i <= n; i++)
        if(!v[i])
            ans++;
    printf("%d\n", ans);
    //system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

int main(){
    int n,i,j,sama=0,x,ganti=0,a=1;
    int A[5005];
    cin >> n;
    for(i=1;i<=n;i++){
        cin >> A[i];
    }
    for(i=1;i<n;i++){
      for(j=1;j<n;j++){
        if(A[j]>A[j+1]){
        swap(A[j],A[j+1]);
        }
      }
    }
    for(i=1;i<=n;i++){
        if(A[i]==A[i+1]){
            A[i] = 0;
        }
        if(A[i]>n){
            A[i] =0;
        }
    }
    for(i=1;i<=n;i++){
        if(A[i]==0){
           ganti++;
        }
    }
   cout << ganti<<endl;
return 0;
}