#include <bits/stdc++.h>
using namespace std;
const long long maxn = 200005;
const long long logn = 32;
long long n, cnt, ans;
long long a[maxn], pos[maxn];
struct nod {
  long long ls, rs;
} tree[maxn * logn];
inline long long read() {
  long long ret = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (isdigit(ch)) {
    ret = ret * 10 + ch - '0';
    ch = getchar();
  }
  return ret * f;
}
long long find(long long l, long long r, long long dep) {
  if (dep == 0) return 0;
  long long l1 = tree[l].ls, r1 = tree[l].rs;
  long long l2 = tree[r].ls, r2 = tree[r].rs;
  bool p1 = l1 && l2, p2 = r1 && r2;
  if (p1 && p2) return min(find(l1, l2, dep - 1), find(r1, r2, dep - 1));
  if (p1) return find(l1, l2, dep - 1);
  if (p2) return find(r1, r2, dep - 1);
  if (l1 && r2) return find(l1, r2, dep - 1) + (1 << dep - 1);
  if (r1 && l2) return find(r1, l2, dep - 1) + (1 << dep - 1);
  return 0;
}
void dfs(long long nod, long long dep) {
  long long ls = tree[nod].ls, rs = tree[nod].rs, p = 1 << dep - 1;
  if (!nod || !dep) return;
  dfs(ls, dep - 1);
  dfs(rs, dep - 1);
  if (ls && rs) ans += find(ls, rs, dep - 1) + p;
}
void add(long long x, long long dep, long long nod) {
  long long p = 1 << dep - 1, val = x & p;
  if (!dep) return;
  if (val) {
    if (!tree[nod].rs) tree[nod].rs = ++cnt;
    add(x, dep - 1, tree[nod].rs);
  } else {
    if (!tree[nod].ls) tree[nod].ls = ++cnt;
    add(x, dep - 1, tree[nod].ls);
  }
}
void scan() {
  n = read();
  cnt = 1;
  for (long long k = 1; k <= n; k++) {
    long long x = read();
    add(x, 31, 1);
  }
}
void solve() {
  dfs(1, 31);
  printf("%lld\n", ans);
}
signed main() {
  scan();
  solve();
  return 0;
}
