#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int son[N << 5][2], idx;
int siz[N << 6];
void insert(int num) {
  int p = 0;
  bitset<31> st(num);
  for (int i = 30; i >= 0; i--) {
    int &ne = son[p][st[i]];
    if (!ne) ne = ++idx;
    p = ne;
    siz[p]++;
  }
}
void del(int num) {
  int p = 0;
  bitset<31> st(num);
  for (int i = 30; i >= 0; i--) {
    int &ne = son[p][st[i]];
    p = ne;
    siz[p]--;
  }
}
int query(int num) {
  int p = 0, ans = 0;
  bitset<31> st(num);
  for (int i = 30; i >= 0; i--) {
    int &ne = son[p][st[i]];
    if (siz[ne])
      p = ne;
    else {
      p = son[p][!st[i]];
      ans += (1 << i);
    }
  }
  return ans;
}
int n, a[N];
int father[N], cnt;
int vis[N];
pair<int, int> p[N];
int find(int x) {
  if (father[x] != x) father[x] = find(father[x]);
  return father[x];
}
void pre() {
  cnt = n;
  for (int i = 1; i <= n; i++) father[i] = i;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) insert(a[i]);
  pre();
  long long ans = 0;
  while (cnt != 1) {
    for (int i = 1; i <= n; i++) {
      int fa = find(i);
      p[i] = make_pair(fa, i);
    }
    sort(p + 1, p + n + 1);
    int sta = 1, preval = p[1].first;
    int pos = 1;
    while (pos <= n) {
      if (cnt == 1) break;
      if (p[pos].first == preval) del(a[p[pos].second]);
      if (pos == n || p[pos + 1].first != preval) {
        int mi = 2e9, demval;
        for (int i = sta; i <= pos; i++) {
          int curval = query(a[p[i].second]);
          if (curval < mi) {
            mi = curval;
            demval = mi ^ a[p[i].second];
          }
        }
        int pos2 = lower_bound(a + 1, a + n + 1, demval) - a;
        int fa2 = find(pos2);
        if (preval != fa2) {
          ans += mi;
          father[preval] = fa2;
          cnt--;
          if (cnt == 1) {
            cout << ans << endl;
            return 0;
          }
        }
        for (int i = sta; i <= pos; i++) insert(a[p[i].second]);
        sta = pos + 1;
        preval = p[sta].first;
      }
      pos++;
    }
  }
  printf("%lld\n", ans);
}
