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

#define whatis(x) cout << #x << " is " << x << endl;

#define MAX 1000001
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265359

#define STDSYNC std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define swap(VAR1,VAR2) VAR1=VAR1^VAR2;VAR2=VAR1^VAR2;VAR1=VAR1^VAR2

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef priority_queue < ll , vector < ll > , greater < ll > > minheap;
typedef priority_queue < ll , vector < ll > , less < ll > > maxheap;

ll arr[1000001];
ll removal[1000001];
ll lefts[10000001];
ll rights[10000001];

int main()
{
	STDSYNC;
	ll rem,a,b,c,i,j,k,n,m;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> arr[i];
	}
	ll ans=0;
	ll maxx=0;
	for(i=0;i<n;i++){
		rem=1;
		if(i==0 || i==n-1)
			rem=max(rem,arr[i]);
		if(i-1>=0){
			rem=max(rem,arr[i]-arr[i-1]);
		}
		if(i+1<n){
			rem=max(rem,arr[i]-arr[i+1]);
		}
		removal[i]=rem;
	}
	for(i=0;i<n;i++){
		arr[i]-=removal[i];
	}
	lefts[0]=0;
	rights[n-1]=0;
	for(i=1;i<n;i++){
		if(arr[i-1]==0)
			lefts[i]=0;
		else
			lefts[i]=min(lefts[i-1]+1,arr[i-1]);
	}
	for(i=n-2;i>=0;i--){
		if(arr[i+1]==0)
			rights[i]=0;
		else
			rights[i]=min(rights[i+1]+1,arr[i+1]);
	}
	maxx=0;
	for(i=1;i<n-1;i++){
		if(arr[i]!=0){
			maxx=max(maxx,(ll)1);
			ll temp=min(lefts[i]+1,rights[i]+1);
			temp=min(temp,arr[i]);
			maxx=max(maxx,temp);
		}
	}
	cout << 1+maxx << endl;
	return 0;
}


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

#define whatis(x) cout << #x << " is " << x << endl;

#define MAX 1000001
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265359

#define STDSYNC std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define swap(VAR1,VAR2) VAR1=VAR1^VAR2;VAR2=VAR1^VAR2;VAR1=VAR1^VAR2

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef priority_queue < ll , vector < ll > , greater < ll > > minheap;
typedef priority_queue < ll , vector < ll > , less < ll > > maxheap;

ll arr[1000001];
ll removal[1000001];

int main()
{
	STDSYNC;
	ll rem,a,b,c,i,j,k,n,m;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> arr[i];
	}
	ll ans=0;
	ll maxx=0;
	for(i=0;i<n;i++){
		rem=1;
		if(i==0 || i==n-1)
			rem=max(rem,arr[i]);
		if(i-1>=0){
			rem=max(rem,arr[i]-arr[i-1]);
		}
		if(i+1<n){
			rem=max(rem,arr[i]-arr[i+1]);
		}
		removal[i]=rem;
	}
	for(i=0;i<n;i++){
		arr[i]-=removal[i];
	}
	maxx=0;
	for(i=1;i<n-1;i++){
		if(arr[i]!=0){
			ll val=1000000000;
			if(arr[i-1]>=arr[i] && arr[i+1]>=arr[i])
				continue;
			if(arr[i-1]<arr[i])
				val=min(val,arr[i-1]+1);
			if(arr[i+1]<arr[i])
				val=min(val,arr[i+1]+1);
			maxx=max(maxx,val);
		}
	}
	cout << 1+maxx << endl;
	return 0;
}


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

#define whatis(x) cout << #x << " is " << x << endl;

#define MAX 1000001
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265359

#define STDSYNC std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define swap(VAR1,VAR2) VAR1=VAR1^VAR2;VAR2=VAR1^VAR2;VAR1=VAR1^VAR2

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef priority_queue < ll , vector < ll > , greater < ll > > minheap;
typedef priority_queue < ll , vector < ll > , less < ll > > maxheap;

ll arr[1000001];
ll removal[1000001];

int main()
{
	STDSYNC;
	ll rem,a,b,c,i,j,k,n,m;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> arr[i];
	}
	ll ans=0;
	ll maxx=0;
	for(i=0;i<n;i++){
		rem=1;
		if(i==0 || i==n-1)
			rem=max(rem,arr[i]);
		if(i-1>=0){
			rem=max(rem,arr[i]-arr[i-1]);
		}
		if(i+1<n){
			rem=max(rem,arr[i]-arr[i+1]);
		}
		removal[i]=rem;
	}
	for(i=0;i<n;i++){
		arr[i]-=removal[i];
	}
	maxx=0;
	for(i=1;i<n-1;i++){
		if(arr[i]!=0)
			maxx=max(maxx,(ll)1);
		if(arr[i-1]==0 || arr[i+1]==0)
			continue;
		else
			maxx=max(maxx,arr[i]);
	}
	cout << 1+maxx << endl;
	return 0;
}


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

#define whatis(x) cout << #x << " is " << x << endl;

#define MAX 1000001
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265359

#define STDSYNC std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define swap(VAR1,VAR2) VAR1=VAR1^VAR2;VAR2=VAR1^VAR2;VAR1=VAR1^VAR2

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef priority_queue < ll , vector < ll > , greater < ll > > minheap;
typedef priority_queue < ll , vector < ll > , less < ll > > maxheap;

ll arr[1000001];
ll removal[1000001];

int main()
{
	STDSYNC;
	ll rem,a,b,c,i,j,k,n,m;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> arr[i];
	}
	ll ans=0;
	ll maxx=0;
	for(i=0;i<n;i++){
		rem=1;
		if(i==0 || i==n-1)
			rem=max(rem,arr[i]);
		if(i-1>=0){
			rem=max(rem,arr[i]-arr[i-1]);
		}
		if(i+1<n){
			rem=max(rem,arr[i]-arr[i+1]);
		}
		removal[i]=rem;
	}
	for(i=0;i<n;i++){
		arr[i]-=removal[i];
	}
	maxx=0;
	for(i=1;i<n-1;i++){
		if(arr[i]!=0){
			ll val=1000000000;
			val=min(val,arr[i-1]+1);
			val=min(val,arr[i+1]+1);
			maxx=max(maxx,val);
		}
	}
	cout << 1+maxx << endl;
	return 0;
}


//bristy-CSE'11
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include <utility>// std::pair
#include<fstream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;

typedef long long LL;
typedef double DD;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<VL> VVI;
typedef pair<LL,LL> PL;
typedef vector<PL> VPL;
typedef map<string,int>MPS;
typedef map<int,int>MPI;
typedef set<LL> ST;
ST::iterator it;
VL::iterator it1;

#define FIR first
#define SC second
#define i64 __int64
#define I64 %I64d
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define S scanf
#define P printf
#define S1(a) scanf("%d",&a)
#define S2(a,b) scanf("d",&a,&b)
#define S3(a,b,c) scanf("d%d",&a,&b,&c)
#define SL(a) scanf("%lld",&a)
#define SL2(a,b) scanf("%lld %lld",&a,&b)
#define SL3(a,b,c) scanf("lld%lld",&a,&b,&c)
#define P1(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PL2(a,b) printf("%lld %lld\n",a,b)
#define PL3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define PC(t) printf("Case %d: ",t)
#define NL printf("\n")
#define REP(i,a,b) for(i=a;i<b;i++)
#define REV(i,a,b)  for(i=a;i>=b;i--)
#define fr(i,a,b) for(i=a;i<=b;i++)
#define IT(x) for(typeof (x.begin())it = x.begin(); it != x.end (); it++)
#define ITV(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) {  cout << *it << " "; } cout <<"\n";
#define ITP(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) {  cout << (*it).FIR << " "<<(*it).SC<<"\n"; } cout << endl;
#define all(x) x.begin(),x.end()
#define rev(a) reverse(BE(a));
#define sorts(a) stable_sort(all(a))
#define sortc(a) sort(all(a),comp)
#define mem(a,b) memset(a,b,sizeof(a))
#define SZ(s) ((int)s.size())
#define even(a) ((a)%2==0)
#define odd(a) ((a)%2==1)
#define max(a,b) (a>b ?a:b)
#define min(a,b) (a<b ?a:b)
#define sqr(a)((a)*(a))
#define area(x1,y1,x2,y2,x3,y3) (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) //Area of a triangle
#define dist(x1,y1,x2,y2) (sqr(x1-x2)+sqr(y1-y2)) //Distance between two points

#define N 1000
#define inf 1e9 //(1<<30)-1
#define eps 1e-14
#define mod 1000000007
#define PI acos(-1.0)//3.141592653589793
#define STN(a) stringtonumber<LL>(a)

struct stc
{
    int fir,sc;
} input[N];

bool comp( stc a, stc b )
{
    return a.fir < b.fir;
}

///lets code///
LL bl[100010];
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
   // freopen("m.txt","r",stdin);
    LL b,i,n,opr,mn,k;
    while(cin>>n)
    {
        fr(i,1,n)
        {
            cin>>bl[i];

        }
        opr=0;
        bl[0]=bl[n+1]=0;
        fr(i,1,n)bl[i]=min(bl[i],min(bl[i-1]+1,bl[i+1]+1));
        REV(i,n,1)
        {
            bl[i]=min(bl[i],min(bl[i-1]+1,bl[i+1]+1));
            opr=max(opr,bl[i]);
        }
        cout<<opr<<endl;

    }

    return 0;
}


//bristy-CSE'11
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include <utility>// std::pair
#include<fstream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;

typedef long long LL;
typedef double DD;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<VL> VVI;
typedef pair<LL,LL> PL;
typedef vector<PL> VPL;
typedef map<string,int>MPS;
typedef map<int,int>MPI;
typedef set<LL> ST;
ST::iterator it;
VL::iterator it1;

#define FIR first
#define SC second
#define i64 __int64
#define I64 %I64d
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define S scanf
#define P printf
#define S1(a) scanf("%d",&a)
#define S2(a,b) scanf("d",&a,&b)
#define S3(a,b,c) scanf("d%d",&a,&b,&c)
#define SL(a) scanf("%lld",&a)
#define SL2(a,b) scanf("%lld %lld",&a,&b)
#define SL3(a,b,c) scanf("lld%lld",&a,&b,&c)
#define P1(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PL2(a,b) printf("%lld %lld\n",a,b)
#define PL3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define PC(t) printf("Case %d: ",t)
#define NL printf("\n")
#define REP(i,a,b) for(i=a;i<b;i++)
#define REV(i,a,b)  for(i=a;i>=b;i--)
#define fr(i,a,b) for(i=a;i<=b;i++)
#define IT(x) for(typeof (x.begin())it = x.begin(); it != x.end (); it++)
#define ITV(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) {  cout << *it << " "; } cout <<"\n";
#define ITP(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) {  cout << (*it).FIR << " "<<(*it).SC<<"\n"; } cout << endl;
#define all(x) x.begin(),x.end()
#define rev(a) reverse(BE(a));
#define sorts(a) stable_sort(all(a))
#define sortc(a) sort(all(a),comp)
#define mem(a,b) memset(a,b,sizeof(a))
#define SZ(s) ((int)s.size())
#define even(a) ((a)%2==0)
#define odd(a) ((a)%2==1)
#define max(a,b) (a>b ?a:b)
#define min(a,b) (a<b ?a:b)
#define sqr(a)((a)*(a))
#define area(x1,y1,x2,y2,x3,y3) (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) //Area of a triangle
#define dist(x1,y1,x2,y2) (sqr(x1-x2)+sqr(y1-y2)) //Distance between two points

#define N 1000
#define inf 1e9 //(1<<30)-1
#define eps 1e-14
#define mod 1000000007
#define PI acos(-1.0)//3.141592653589793
#define STN(a) stringtonumber<LL>(a)

struct stc
{
    int fir,sc;
} input[N];

bool comp( stc a, stc b )
{
    return a.fir < b.fir;
}

///lets code///
LL bl[100010];
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    freopen("m.txt","r",stdin);
    LL b,i,n,opr,mn,k;
    while(cin>>n)
    {
        fr(i,1,n)
        {
            cin>>bl[i];

        }
        opr=0;
        bl[0]=bl[n+1]=0;
        fr(i,1,n)bl[i]=min(bl[i],min(bl[i-1]+1,bl[i+1]+1));
        fr(i,1,n)
        {
            bl[i]=min(bl[i],min(bl[i-1]+1,bl[i+1]+1));
            opr=max(opr,bl[i]);
        }
        cout<<opr<<endl;

    }

    return 0;
}


//bristy-CSE'11
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include <utility>// std::pair
#include<fstream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;

typedef long long LL;
typedef double DD;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<VL> VVI;
typedef pair<LL,LL> PL;
typedef vector<PL> VPL;
typedef map<string,int>MPS;
typedef map<int,int>MPI;
typedef set<LL> ST;
ST::iterator it;
VL::iterator it1;

#define FIR first
#define SC second
#define i64 __int64
#define I64 %I64d
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define S scanf
#define P printf
#define S1(a) scanf("%d",&a)
#define S2(a,b) scanf("d",&a,&b)
#define S3(a,b,c) scanf("d%d",&a,&b,&c)
#define SL(a) scanf("%lld",&a)
#define SL2(a,b) scanf("%lld %lld",&a,&b)
#define SL3(a,b,c) scanf("lld%lld",&a,&b,&c)
#define P1(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PL2(a,b) printf("%lld %lld\n",a,b)
#define PL3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define PC(t) printf("Case %d: ",t)
#define NL printf("\n")
#define REP(i,a,b) for(i=a;i<b;i++)
#define REV(i,a,b)  for(i=a;i>=b;i--)
#define fr(i,a,b) for(i=a;i<=b;i++)
#define IT(x) for(typeof (x.begin())it = x.begin(); it != x.end (); it++)
#define ITV(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) {  cout << *it << " "; } cout <<"\n";
#define ITP(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) {  cout << (*it).FIR << " "<<(*it).SC<<"\n"; } cout << endl;
#define all(x) x.begin(),x.end()
#define rev(a) reverse(BE(a));
#define sorts(a) stable_sort(all(a))
#define sortc(a) sort(all(a),comp)
#define mem(a,b) memset(a,b,sizeof(a))
#define SZ(s) ((int)s.size())
#define even(a) ((a)%2==0)
#define odd(a) ((a)%2==1)
#define max(a,b) (a>b ?a:b)
#define min(a,b) (a<b ?a:b)
#define sqr(a)((a)*(a))
#define area(x1,y1,x2,y2,x3,y3) (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) //Area of a triangle
#define dist(x1,y1,x2,y2) (sqr(x1-x2)+sqr(y1-y2)) //Distance between two points

#define N 1000
#define inf 1e9 //(1<<30)-1
#define eps 1e-14
#define mod 1000000007
#define PI acos(-1.0)//3.141592653589793
#define STN(a) stringtonumber<LL>(a)

struct stc
{
    int fir,sc;
} input[N];

bool comp( stc a, stc b )
{
    return a.fir < b.fir;
}

///lets code///
LL bl[100010];
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
   // freopen("m.txt","r",stdin);
    LL b,i,n,opr,mn,k;
    while(cin>>n)
    {
        fr(i,1,n)
        {
            cin>>bl[i];

        }
        opr=0;
        bl[0]=bl[n+1]=0;
        fr(i,1,n)bl[i]=min(bl[i],min(bl[i-1]+1,bl[i+1]+1));
        fr(i,1,n)
        {
            bl[i]=min(bl[i],min(bl[i-1]+1,bl[i+1]+1));
            opr=max(opr,bl[i]);
        }
        cout<<opr<<endl;

    }

    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long n,a[100000],i,j,in,m,c=0;
	cin>>n;
	for(i=0;i<n;i++)
	scanf("%ld",&a[i]);//a[i];
	while(1)
	{
		in=0;n--;
		for(i=1;i<n;i++)
		{
			m=min(a[i-1],a[i+1]);
			if(m>=a[i])
			{

				if(a[i]-1!=0)
				{
					a[in++]=a[i]-1;
				}
			}
			else
			{
				a[in++]=m;

			}

		}
		if(in!=0)
		{
			n=in;
			in=0;
			c++;
		}
		else
		break;
	}
	cout<<c+1;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long n,a[100000],i,j,in,m,c=0;
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i];
	while(1)
	{
		in=0;n--;
		for(i=1;i<n;i++)
		{
			m=min(a[i-1],a[i+1]);
			if(m>=a[i])
			{

				if(a[i]-1!=0)
				{
					a[in++]=a[i]-1;
				}
			}
			else
			{
				a[in++]=m;

			}

		}
		if(in!=0)
		{
			n=in;
			in=0;
			c++;
		}
		else
		break;
	}
	cout<<c+1;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	long n,a[100000],i,j,in,m,c=0;
	cin>>n;
	for(i=0;i<n;i++)
	scanf("%ld",&a[i]);//a[i];
	while(1)
	{
		in=0;n--;
		for(i=1;i<n;i++)
		{
			m=min(a[i-1],a[i+1]);
			if(m>=a[i])
			{

				if(a[i]-1!=0)
				{
					a[in++]=a[i]-1;
				}
			}
			else
			{
				a[in++]=m;

			}

		}
		if(in!=0)
		{
			n=in;
			in=0;
			c++;
		}
		else
		break;
	}
	cout<<c+1;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	long n,a[100000],i,j,in,m,c=0,dp[100000],max;
	cin>>n;
	for(i=0;i<n;i++)
	scanf("%ld",&a[i]);//a[i];
	dp[0]=1;
     for(i=1;i<n;i++)
     {
     	dp[i]=min(a[i],min(i+1,dp[i-1]+1));
	 }

	 dp[n-1]=1;
	 for(i=n-2;i>=0;i--)
	 {
	 	dp[i]=min(dp[i],min(a[i],min(n-i,dp[i+1]+1)));
	 }

	max=0;
	for(i=0;i<n;i++)
	if(dp[i]>max)
	max=dp[i];
	cout<<max;
}


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

const int maxl=2e5+10;

int n,m,cnt,tot,cas,ans;
int a[maxl],b[maxl],num[maxl*32];
int ind[maxl*32],sz[maxl*32],tr[maxl*32][2];
bool vis[maxl],pr[maxl];
char s[maxl];
vector<int> e[maxl];

inline void prework()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		int u=0,c;
		for(int j=30;j>=0;j--)
		{
			c=(a[i]>>j)&1;
			if(!tr[u][c])
				tr[u][c]=++tot;
			u=tr[u][c];++num[u];
		}
		ind[u]=i;
	}
	for(int i=1;i<=n;i++)
	{
		int u=0,c;bool flag=true;
		for(int j=30;j>=0;j--)
		{
			c=(a[i]>>j)&1;
			if(flag)
			{
				if(num[tr[u][c]]==1)
					c^=1,flag=false;
			}
			else
			{
				if(!tr[u][c])
					c^=1;
			}
			u=tr[u][c];
		}
		b[i]=ind[u];
		e[b[i]].push_back(i);
	}
}

inline void dfs(int u)
{
	vis[u]=true;++cnt;
	for(int v:e[u])
	if(!vis[v])
		dfs(v);
}

inline void mainwork()
{
	ans=n-2;int sum=0,mx=0;
	for(int i=1;i<=n;i++)
	if(!vis[i])
	{
		if(b[b[i]]==i)
		{
			vis[i]=true;vis[b[i]]=true;
			pr[i]=true;pr[b[i]]=true;
			cnt=0;dfs(i);sz[i]=cnt;
			cnt=0;dfs(b[i]);sz[b[i]]=cnt;
			ans=min(ans,n-sz[i]-sz[b[i]]);
			sum+=max(sz[i],sz[b[i]]);
			mx=max(mx,min(sz[i],sz[b[i]]));
		}
	}
	sum+=mx;
	ans=min(ans,n-sum);
}

inline void print()
{
	printf("%d\n",ans);
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(cas=1;cas<=t;cas++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}


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

const int maxl=2e5+10;

int n,m,cnt,tot,cas,ans;
int a[maxl],b[maxl];
int ind[maxl*32],num[maxl*32],tr[maxl*32][2];
bool vis[maxl];
char s[maxl];
vector<int> e[maxl];

inline void prework()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		int u=0,c;
		for(int j=30;j>=0;j--)
		{
			c=(a[i]>>j)&1;
			if(!tr[u][c])
				tr[u][c]=++tot;
			u=tr[u][c];++num[u];
		}
		ind[u]=i;
	}
	for(int i=1;i<=n;i++)
	{
		int u=0,c;bool flag=true;
		for(int j=30;j>=0;j--)
		{
			c=(a[i]>>j)&1;
			if(flag)
			{
				if(num[tr[u][c]]==1)
					c^=1,flag=false;
			}
			else
			{
				if(!tr[u][c])
					c^=1;
			}
			u=tr[u][c];
		}
		b[i]=ind[u];
		e[b[i]].push_back(i);
	}
}

inline void dfs(int u)
{
	vis[u]=true;++cnt;
	for(int v:e[u])
	if(!vis[v])
		dfs(v);
}

inline void mainwork()
{
	ans=0;
	for(int i=1;i<=n;i++)
	if(!vis[i])
	{
		if(b[b[i]]==i)
		{
			vis[i]=true;vis[b[i]]=true;
			ans++;
		}
	}
	if(ans>0)
		--ans;
}

inline void print()
{
	printf("%d\n",ans);
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(cas=1;cas<=t;cas++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}


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

const int maxl=2e5+10;

int n,m,cnt,tot,cas,ans;
int a[maxl],b[maxl],num[maxl*32];
int ind[maxl*32],sz[maxl*32],tr[maxl*32][2];
bool vis[maxl],pr[maxl];
char s[maxl];
vector<int> e[maxl];

inline void prework()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		int u=0,c;
		for(int j=30;j>=0;j--)
		{
			c=(a[i]>>j)&1;
			if(!tr[u][c])
				tr[u][c]=++tot;
			u=tr[u][c];++num[u];
		}
		ind[u]=i;
	}
}

inline int dfs(int u)
{
	if(!tr[u][0] && !tr[u][1])
		return 1;
	int l=0,r=0;
	if(tr[u][0])
		l=dfs(tr[u][0]);
	if(tr[u][1])
		r=dfs(tr[u][1]);
	if(!tr[u][1])
		return l;
	if(!tr[u][0])
		return r;
	return max(l,r)+1;
}

inline void mainwork()
{
	ans=n-dfs(0);
}

inline void print()
{
	printf("%d\n",ans);
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(cas=1;cas<=t;cas++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
const int LOG = 30;
const int MAX = 4e5+5;
struct node {
    int go[LOG+2];
    int num;
    node() {
        for (int i = 0; i < LOG+2; i++) go[i] = MAX-1;
        num = 0;
    }
};
node dat[MAX];
int cur = 1;
void ins(int x) {
    int at = 0;
    dat[at].num++;
    int to = bits(x)+1;
    if (x == 0) to = 0;
    if (dat[at].go[to] == MAX-1) {
        dat[at].go[to] = cur++;
    }
    at = dat[at].go[to];
    if (x) x = (x^(1<<(to-1)));
    while (true) {
        dat[at].num++;
        if (x == 0) break;
        int to = bits(x)+1;
        if (x == 0) to = 0;
        if (dat[at].go[to] == MAX-1) {
            dat[at].go[to] = cur++;
        }
        at = dat[at].go[to];
        x = x^(1<<(to-1));
    }
}

int main() {
    setIO("");
    int n; re(n);
    auto high_bit = [&](int x) -> int {
        for (int i = LOG; i >= 0; i--) {
            if ((1<<i)&x) return i;
        }
        return LOG+1;
    };
    vi a(n);
    f0r(i, n) re(a[i]);
    f0r(i, n) ins(a[i]);
    function<int(int)> dfs = [&](int src) -> int {
        int ret = 0;
        vector<int> pre(LOG+2);
        vector<int> suf(LOG+2);
        for (int i = LOG+1; i >= 0; i--) {
            if (i == LOG+1) suf[i] = min(1, dat[dat[src].go[i]].num);
            else suf[i] = suf[i+1] + min(1, dat[dat[src].go[i]].num);
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (i == 0) pre[i] = min(1, dat[dat[src].go[i]].num);
            else pre[i] = max(pre[i-1], min(1, dat[dat[src].go[i]].num));
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (dat[src].go[i] == MAX-1) continue;
            int bef = (i ? pre[i-1] : 0);
            int aft = (i == LOG+1 ? 0 : suf[i+1]);
            int res = bef + dfs(dat[src].go[i]) + aft;
            ckmax(ret, res);
        }
        int val = min(2, dat[src].num);
        ckmax(ret, val);
        return ret;
    };
    int ans = dfs(0);
    ps(n-ans);
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
const int LOG = 30;
const int MAX = 4e5+5;
struct node {
    int go[LOG+2];
    int num;
    node() {
        for (int i = 0; i < LOG+2; i++) go[i] = MAX-1;
        num = 0;
    }
};
node dat[MAX];
int cur = 1;
void ins(int x) {
    int at = 0;
    dat[at].num++;
    int to = bits(x)+1;
    if (x == 0) to = 0;
    if (dat[at].go[to] == MAX-1) {
        dat[at].go[to] = cur++;
    }
    at = dat[at].go[to];
    if (x) x = (x^(1<<(to-1)));
    while (true) {
        dat[at].num++;
        if (x == 0) break;
        int to = bits(x)+1;
        if (x == 0) to = 0;
        if (dat[at].go[to] == MAX-1) {
            dat[at].go[to] = cur++;
        }
        at = dat[at].go[to];
        x = x^(1<<(to-1));
    }
}

int main() {
    setIO("");
    int n; re(n);
    auto high_bit = [&](int x) -> int {
        for (int i = LOG; i >= 0; i--) {
            if ((1<<i)&x) return i;
        }
        return LOG+1;
    };
    vi a(n);
    f0r(i, n) re(a[i]);
    f0r(i, n) ins(a[i]);
    function<int(int)> dfs = [&](int src) -> int {
        int ret = 0;
        vector<int> pre(LOG+2);
        vector<int> suf(LOG+2);
        for (int i = LOG+1; i >= 0; i--) {
            if (i == LOG+1) suf[i] = min(1, dat[dat[src].go[i]].num);
            else suf[i] = suf[i+1] + min(1, dat[dat[src].go[i]].num);
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (i == 0) pre[i] = min(1, dat[dat[src].go[i]].num);
            else pre[i] = max(pre[i-1], min(1, dat[dat[src].go[i]].num));
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (dat[src].go[i] == MAX-1) continue;
            int bef = (i ? pre[i-1] : 0);
            int aft = (i == LOG+1 ? 0 : suf[i+1]);
            if (src == 0 && i == 2) {
                ps(dfs(dat[src].go[i]), dat[dat[src].go[i]].num, bef, aft);
            }
            int res = bef + dfs(dat[src].go[i]) + aft;
            ckmax(ret, res);
        }
        int val = min(2, dat[src].num);
        ckmax(ret, val);
        return ret;
    };
    int ans = dfs(0);
    ps(n-ans);
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
const int LOG = 30;
const int MAX = 4e5+5;
struct node {
    int go[LOG+2];
    node() {
        for (int i = 0; i < LOG+2; i++) go[i] = MAX-1;
    }
    int num;
};
node dat[MAX];
int cur = 1;
void ins(int x) {
    int at = 0;
    dat[at].num++;
    int to = bits(x)+1;
    if (x == 0) to = 0;
    if (dat[at].go[to] == MAX-1) {
        dat[at].go[to] = cur++;
    }
    at = dat[at].go[to];
    if (x) x = (x^(1<<(to-1)));
    while (true) {
        dat[at].num++;
        if (x == 0) break;
        int to = bits(x)+1;
        if (x == 0) to = 0;
        if (dat[at].go[to] == MAX-1) {
            dat[at].go[to] = cur++;
        }
        at = dat[at].go[to];
        x = x^(1<<(to-1));
    }
}

int main() {
//    setIO("");
    int n; re(n);
    auto high_bit = [&](int x) -> int {
        for (int i = LOG; i >= 0; i--) {
            if ((1<<i)&x) return i;
        }
        return LOG+1;
    };
    vi a(n);
    f0r(i, n) re(a[i]);
    f0r(i, n) ins(a[i]);
    function<int(int)> dfs = [&](int src) -> int {
        int ret = 0;
        vector<int> pre(LOG+2);
        vector<int> suf(LOG+2);
        for (int i = LOG+1; i >= 0; i--) {
            if (i == LOG+1) suf[i] = min(1, dat[dat[src].go[i]].num);
            else suf[i] = suf[i+1] + min(1, dat[dat[src].go[i]].num);
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (dat[src].go[i] == MAX-1) continue;
            int bef = (i ? min(1, dat[dat[src].go[i-1]].num) : 0);
            int aft = (i == LOG+1 ? 0 : suf[i+1]);
            int val = min(2, dat[src].num);
            ckmax(val, dfs(dat[src].go[i]));
            int res = bef + val + aft;
            ckmax(ret, res);
        }
        int val = min(2, dat[src].num);
        ckmax(ret, val);
        return ret;
    };
    int ans = dfs(0);
    ps(n-ans);
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
const int LOG = 30;
const int MAX = 4e5+5;
struct node {
    int go[LOG+2];
    node() {
        for (int i = 0; i < LOG+2; i++) go[i] = MAX-1;
    }
    int num;
};
node dat[MAX];
int cur = 1;
void ins(int x) {
    int at = 0;
    dat[at].num++;
    int to = bits(x)+1;
    if (x == 0) to = 0;
    if (dat[at].go[to] == MAX-1) {
        dat[at].go[to] = cur++;
    }
    at = dat[at].go[to];
    if (x) x = (x^(1<<(to-1)));
    while (true) {
        dat[at].num++;
        if (x == 0) break;
        int to = bits(x)+1;
        if (x == 0) to = 0;
        if (dat[at].go[to] == MAX-1) {
            dat[at].go[to] = cur++;
        }
        at = dat[at].go[to];
        x = x^(1<<(to-1));
    }
}

int main() {
//    setIO("");
    int n; re(n);
    auto high_bit = [&](int x) -> int {
        for (int i = LOG; i >= 0; i--) {
            if ((1<<i)&x) return i;
        }
        return LOG+1;
    };
    vi a(n);
    f0r(i, n) re(a[i]);
    f0r(i, n) ins(a[i]);
    function<int(int)> dfs = [&](int src) -> int {
        int ret = 0;
        vector<int> pre(LOG+2);
        vector<int> suf(LOG+2);
        for (int i = LOG+1; i >= 0; i--) {
            if (i == LOG+1) suf[i] = min(1, dat[dat[src].go[i]].num);
            else suf[i] = suf[i+1] + min(1, dat[dat[src].go[i]].num);
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (dat[src].go[i] == MAX-1) continue;
            int bef = (i ? min(1, dat[dat[src].go[i-1]].num) : 0);
            int aft = (i == LOG+1 ? 0 : suf[i+1]);
            int res = bef + dfs(dat[src].go[i]) + aft;
            ckmax(ret, res);
        }
        int val = min(2, dat[src].num);
        ckmax(ret, val);
        return ret;
    };
    int ans = dfs(0);
    ps(n-ans);
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
const int LOG = 30;
const int MAX = 5e6;
struct node {
    map<int, int> go;
    int num;
    node() {
        num = 0;
    }
};
node dat[MAX];
int cur = 1;
void ins(int x) {
    int at = 0;
    dat[at].num++;
    int to = bits(x)+1;
    if (x == 0) to = 0;
    if (dat[at].go.find(to) == dat[at].go.end()) {
        assert(cur<MAX-1);
        dat[at].go[to] = cur++;
    }
    at = dat[at].go[to];
    if (x) x = (x^(1<<(to-1)));
    while (true) {
        dat[at].num++;
        if (x == 0) break;
        int to = bits(x)+1;
        if (x == 0) to = 0;
        if (dat[at].go.find(to) == dat[at].go.end()) {
            assert(cur<MAX-1);
            dat[at].go[to] = cur++;
        }
        at = dat[at].go[to];
        x = x^(1<<(to-1));
    }
}

int main() {
    setIO("");
    int n; re(n);
    auto high_bit = [&](int x) -> int {
        for (int i = LOG; i >= 0; i--) {
            if ((1<<i)&x) return i;
        }
        return LOG+1;
    };
    vi a(n);
    f0r(i, n) re(a[i]);
    f0r(i, n) ins(a[i]);
    function<int(int)> dfs = [&](int src) -> int {
        int ret = 0;
        vector<int> pre(LOG+2);
        vector<int> suf(LOG+2);
        for (int i = LOG+1; i >= 0; i--) {
            int val = 0;
            if (dat[src].go.find(i) != dat[src].go.end()) val = dat[dat[src].go[i]].num;
            if (i == LOG+1) suf[i] = min(1, val);
            else suf[i] = suf[i+1] + min(1, val);
        }
        for (int i = 0; i <= LOG+1; i++) {
            int val = 0;
            if (dat[src].go.find(i) != dat[src].go.end()) val = dat[dat[src].go[i]].num;
            if (i == 0) pre[i] = min(1, val);
            else pre[i] = max(pre[i-1], min(1, val));
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (dat[src].go.find(i) == dat[src].go.end()) continue;
            int bef = (i ? pre[i-1] : 0);
            int aft = (i == LOG+1 ? 0 : suf[i+1]);
            int res = bef + dfs(dat[src].go[i]) + aft;
            ckmax(ret, res);
        }
        int val = min(2, dat[src].num);
        ckmax(ret, val);
        return ret;
    };
    int ans = dfs(0);
    ps(n-ans);
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
const int LOG = 30;
const int MAX = 1e7;
struct node {
    map<int, int> go;
    int num;
    node() {
        num = 0;
    }
};
node dat[MAX];
int cur = 1;
void ins(int x) {
    int at = 0;
    dat[at].num++;
    int to = bits(x)+1;
    if (x == 0) to = 0;
    if (dat[at].go.find(to) == dat[at].go.end()) {
        assert(cur<MAX-1);
        dat[at].go[to] = cur++;
    }
    at = dat[at].go[to];
    if (x) x = (x^(1<<(to-1)));
    while (true) {
        dat[at].num++;
        if (x == 0) break;
        int to = bits(x)+1;
        if (x == 0) to = 0;
        if (dat[at].go.find(to) == dat[at].go.end()) {
            assert(cur<MAX-1);
            dat[at].go[to] = cur++;
        }
        at = dat[at].go[to];
        x = x^(1<<(to-1));
    }
}

int main() {
    setIO("");
    int n; re(n);
    auto high_bit = [&](int x) -> int {
        for (int i = LOG; i >= 0; i--) {
            if ((1<<i)&x) return i;
        }
        return LOG+1;
    };
    vi a(n);
    f0r(i, n) re(a[i]);
    f0r(i, n) ins(a[i]);
    function<int(int)> dfs = [&](int src) -> int {
        int ret = 0;
        vector<int> pre(LOG+2);
        vector<int> suf(LOG+2);
        for (int i = LOG+1; i >= 0; i--) {
            int val = 0;
            if (dat[src].go.find(i) != dat[src].go.end()) val = dat[dat[src].go[i]].num;
            if (i == LOG+1) suf[i] = min(1, val);
            else suf[i] = suf[i+1] + min(1, val);
        }
        for (int i = 0; i <= LOG+1; i++) {
            int val = 0;
            if (dat[src].go.find(i) != dat[src].go.end()) val = dat[dat[src].go[i]].num;
            if (i == 0) pre[i] = min(1, val);
            else pre[i] = max(pre[i-1], min(1, val));
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (dat[src].go.find(i) == dat[src].go.end()) continue;
            int bef = (i ? pre[i-1] : 0);
            int aft = (i == LOG+1 ? 0 : suf[i+1]);
            int res = bef + dfs(dat[src].go[i]) + aft;
            ckmax(ret, res);
        }
        int val = min(2, dat[src].num);
        ckmax(ret, val);
        return ret;
    };
    int ans = dfs(0);
    ps(n-ans);
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
const int LOG = 30;
const int MAX = (2e5+5)*5;
struct node {
    int go[LOG+2];
    int num;
    node() {
        for (int i = 0; i < LOG+2; i++) go[i] = MAX-1;
        num = 0;
    }
};
node dat[MAX];
int cur = 1;
void ins(int x) {
    int at = 0;
    dat[at].num++;
    int to = bits(x)+1;
    if (x == 0) to = 0;
    if (dat[at].go[to] == MAX-1) {
        dat[at].go[to] = cur++;
    }
    at = dat[at].go[to];
    if (x) x = (x^(1<<(to-1)));
    while (true) {
        dat[at].num++;
        if (x == 0) break;
        int to = bits(x)+1;
        if (x == 0) to = 0;
        if (dat[at].go[to] == MAX-1) {
            dat[at].go[to] = cur++;
        }
        at = dat[at].go[to];
        x = x^(1<<(to-1));
    }
}

int main() {
    setIO("");
    int n; re(n);
    auto high_bit = [&](int x) -> int {
        for (int i = LOG; i >= 0; i--) {
            if ((1<<i)&x) return i;
        }
        return LOG+1;
    };
    vi a(n);
    f0r(i, n) re(a[i]);
    f0r(i, n) ins(a[i]);
    function<int(int)> dfs = [&](int src) -> int {
        int ret = 0;
        vector<int> pre(LOG+2);
        vector<int> suf(LOG+2);
        for (int i = LOG+1; i >= 0; i--) {
            if (i == LOG+1) suf[i] = min(1, dat[dat[src].go[i]].num);
            else suf[i] = suf[i+1] + min(1, dat[dat[src].go[i]].num);
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (i == 0) pre[i] = min(1, dat[dat[src].go[i]].num);
            else pre[i] = max(pre[i-1], min(1, dat[dat[src].go[i]].num));
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (dat[src].go[i] == MAX-1) continue;
            int bef = (i ? pre[i-1] : 0);
            int aft = (i == LOG+1 ? 0 : suf[i+1]);
            int res = bef + dfs(dat[src].go[i]) + aft;
            ckmax(ret, res);
        }
        int val = min(2, dat[src].num);
        ckmax(ret, val);
        return ret;
    };
    int ans = dfs(0);
    ps(n-ans);
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
int solve(vector<int> a, int b) {
    if (sz(a) == 0) return 0;
    if (sz(a) == 1) return 1;
    vector<vi> use(2);
    f0r(i, sz(a)) {
        if (a[i]&(1<<b)) use[1].eb(a[i]);
        else use[0].eb(a[i]);
    }
    if (sz(use[0]) == 0) return solve(use[1], b-1);
    else if (sz(use[1]) == 0) return solve(use[0], b-1);
    int v1 = solve(use[0], b-1);
    int v2 = solve(use[1], b-1);
    return 1 + max(v1, v2);
}
int main() {
    setIO("");
    int n; re(n);
    vi a(n);
    f0r(i, n) re(a[i]);
    ps(n-solve(a, 29));
    return 0;
}