#include <bits/stdc++.h>
using namespace std;
int n, lef[200005 * 30], ri[200005 * 30], tree[200005 * 30], cnt = 1;
vector<int> vt[200005 * 30];
long long int an = 0;
void update(int node, int val, int now, int mul) {
  if (now == -1)
    vt[node].push_back(mul);
  else if ((1 << now) & val) {
    if (ri[node])
      update(ri[node], val, now - 1, 1 << now);
    else {
      cnt++;
      ri[node] = cnt;
      update(ri[node], val, now - 1, 1 << now);
    }
    if (tree[ri[node]] != vt[ri[node]].size()) cout << "fault" << endl;
    vt[node].push_back(vt[ri[node]][tree[ri[node]] - 1] + mul);
  } else {
    if (lef[node])
      update(lef[node], val, now - 1, 0);
    else {
      cnt++;
      lef[node] = cnt;
      update(lef[node], val, now - 1, 0);
    }
    if (tree[lef[node]] != vt[lef[node]].size()) cout << "fault" << endl;
    vt[node].push_back(vt[lef[node]][tree[lef[node]] - 1] + mul);
  }
  tree[node]++;
}
long long int query(int node, int val, int now) {
  if (now == -1) return 0LL;
  long long int tmp = 0;
  if ((1 << now) & val) {
    if (ri[node] == 0) {
      tmp = (1 << now) + query(lef[node], val, now - 1);
    } else if (ri[node]) {
      tmp = query(ri[node], val, now - 1);
    }
  } else {
    if (lef[node] == 0) {
      tmp = (1 << now) + query(ri[node], val, now - 1);
    } else if (lef[node]) {
      tmp = query(lef[node], val, now - 1);
    }
  }
  return tmp;
}
void process(int node, int now) {
  if (now == -1) return;
  long long int tmp = 1e18;
  for (int i = 0; i < vt[lef[node]].size(); i++) {
    if (ri[node]) tmp = min(tmp, query(ri[node], vt[lef[node]][i], now - 1));
  }
  if (tmp < 1e18) an += (tmp + (1 << now));
  if (lef[node]) process(lef[node], now - 1);
  if (ri[node]) process(ri[node], now - 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  scanf("%d", &n);
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    update(1, x, 30, 0);
  }
  process(1, 30);
  printf("%lld\n", an);
  return 0;
}
