#include <bits/stdc++.h>
using namespace std;
const int N = 6000009, SIZE = 1 << 21;
int n, a[N], tot, trie[N][2], root, l[N], r[N];
char ibuf[SIZE], *iS, *iT;
template <class I>
inline void read(I &x) {
  int f;
  char c;
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-') f = -1;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  x = f == -1 ? -x : x;
}
void add(int &p, int x, int dep) {
  if (!p) p = ++tot;
  l[p] = min(l[p], x), r[p] = max(r[p], x);
  if (dep < 0) return;
  int son = (a[x] >> dep) & 1;
  add(trie[p][son], x, dep - 1);
}
long long find(int p, int val, int dep) {
  if (dep < 0) return 0;
  int son = (val >> dep) & 1;
  if (trie[p][son]) return find(trie[p][son], val, dep - 1);
  return find(trie[p][son ^ 1], val, dep - 1) | (1 << dep);
}
long long dfs(int p, int dep) {
  if (dep < 0) return 0;
  int x = trie[p][0], y = trie[p][1];
  if (r[x] && r[y]) {
    long long minn = 1e18;
    for (int i = l[x]; i <= r[x]; ++i) minn = min(minn, find(y, a[i], dep - 1));
    return minn + dfs(x, dep - 1) + dfs(y, dep - 1) + (1 << dep);
  }
  if (r[x]) return dfs(x, dep - 1);
  if (r[y]) return dfs(y, dep - 1);
  return 0;
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]);
  sort(a + 1, a + n + 1);
  memset(l, 0x3f, sizeof(l));
  for (int i = 1; i <= n; ++i) add(root, i, 30);
  printf("%lld\n", dfs(root, 30));
  return 0;
}
