#include <bits/stdc++.h>
using namespace std;
void rd(long long &x) {
  x = 0;
  long long f = 1;
  char ch = (getchar());
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = (getchar());
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = (getchar());
  x *= f;
}
const long long N = 2e5 + 5;
const long long INF = 1e18;
long long n, rt;
long long a[N];
struct Trie {
  long long cnt;
  long long ch[N * 30][2];
  void insert(long long &u, long long k, long long d) {
    if (!u) u = ++cnt;
    if (d < 0) return;
    insert(ch[u][k >> d & 1], k, d - 1);
  }
  long long qry(long long u, long long v, long long d) {
    if (!u || !v) return INF;
    if (d < 0) return 0;
    long long res =
        min(qry(ch[u][0], ch[v][0], d - 1), qry(ch[u][1], ch[v][1], d - 1));
    if (res < INF) return res;
    return min(qry(ch[u][0], ch[v][1], d - 1), qry(ch[u][1], ch[v][0], d - 1)) +
           (1ll << d);
  }
  long long ask(long long u, long long d) {
    if (d < 0) return 0;
    long long res = 0;
    if (ch[u][0] && ch[u][1])
      res += qry(ch[u][0], ch[u][1], d - 1) + (1ll << d);
    if (ch[u][0]) res += ask(ch[u][0], d - 1);
    if (ch[u][1]) res += ask(ch[u][1], d - 1);
    return res;
  }
} T;
signed main() {
  rd(n);
  for (long long i = 1; i <= n; ++i) rd(a[i]);
  sort(a + 1, a + n + 1);
  n = unique(a + 1, a + n + 1) - a - 1;
  for (long long i = 1; i <= n; ++i) T.insert(rt, a[i], 30);
  cout << T.ask(rt, 30);
  return 0;
}
