#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int z = N * 32;
int n, a[N], f[N], rt;
int pool[z], tp, cnt, ch[z][2];
long long ans;
int fa(int x) {
  if (x == f[x]) return x;
  return f[x] = fa(f[x]);
}
void uni(int x, int y) {
  x = fa(x), y = fa(y);
  if (x == y) return;
  f[x] = y;
}
int newnode() {
  if (!tp) return ++cnt;
  return pool[tp--];
}
void ins(int v) {
  int no = rt, x;
  for (register int i = 30; i >= 0; --i) {
    if (v & (1 << i))
      x = 1;
    else
      x = 0;
    if (!ch[no][x]) ch[no][x] = newnode();
    no = ch[no][x];
  }
}
void clr(int x) {
  if (ch[x][0]) clr(ch[x][0]);
  if (ch[x][1]) clr(ch[x][1]);
  pool[++tp] = x;
  ch[x][0] = ch[x][1] = 0;
}
int find_min(int v) {
  int no = rt, ans = 0, x;
  for (register int i = 30; i >= 0; --i) {
    if (v & (1 << i))
      x = 1;
    else
      x = 0;
    if (!ch[no][x])
      ans = ans * 2 + 1, no = ch[no][x ^ 1];
    else
      ans = ans * 2, no = ch[no][x];
  }
  return ans;
}
void solve(vector<int> x, int d) {
  int s = x.size();
  if (s <= 1) return;
  if (d == -1) {
    int no = x[0];
    for (register int i = 1; i < s; ++i) {
      uni(no, x[i]);
      no = x[i];
    }
    return;
  }
  vector<int> l, r;
  int no;
  for (register int i = 0; i < s; ++i) {
    no = x[i];
    if (a[no] & (1 << d))
      l.push_back(no);
    else
      r.push_back(no);
  }
  solve(l, d - 1);
  solve(r, d - 1);
  int sl = l.size(), sr = r.size();
  if (sl == 0 || sr == 0) return;
  int q = (1 << d) - 1;
  rt = newnode();
  for (register int i = 0; i < sl; ++i) {
    no = l[i];
    ins(a[no] & q);
  }
  int f = a[l[0]] ^ a[r[0]];
  for (register int i = 0; i < sr; ++i) {
    no = r[i];
    f = min(f, find_min(a[no] & q));
  }
  uni(l[0], r[0]);
  clr(rt);
  ans += f + (1 << d);
}
int main() {
  scanf("%d", &n);
  vector<int> c;
  for (register int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    c.push_back(i);
  }
  solve(c, 29);
  printf("%lld", ans);
  return 0;
}
