//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

typedef pair<int,int> P;
typedef long long ll;



__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
vector<ll> b;
int dfs(int beg,int en,ll k,ll km,int ans){
  auto x = lower_bound(b.begin()+beg,b.begin()+en,k)-b.begin();
  //cout << beg << " " << en << " " << x << " " << k << endl;
  if(x == beg){
    if(k%2)return ans;
    //cout << beg << " " << en << endl;
    return dfs(beg,en,k+(km/2),km/2,ans);
  }else if(x == en && k > b[en]){
    if(k%2)return ans;
    //cout << beg << " " << en << endl;
    return dfs(beg,en,k-(km/2),km/2,ans);
  }else{
    ans += km;
    if(k%2)return ans;
    //cout << x << " " << en  << ":"  << beg << " " << x-1<< endl;
    return min(dfs(x,en,k+(km/2),km/2,ans),dfs(beg,x-1,k-(km/2),km/2,ans));
  }
}
int main() { 
  int n;cin>>n;
  ll a[n];
  for(int i = 0; n > i; i++){
    cin>>a[i];
    b.push_back(a[i]);
  }
  sort(b.begin(),b.end());
  //b.push_back((2LL<<30LL));
  cout << dfs(0,n-1,(2LL<<29LL),(2LL<<29LL),0) << endl;
}