#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)2e5 + 19;
int trie[maxn << 5][2];
int tot, A[maxn], n;
void inittrie() {
  for (int i = 1; i <= tot; ++i) trie[i][0] = trie[i][1] = 0;
  tot = 1;
}
void ins(int x) {
  int now = 1;
  for (int i = 29; i >= 0; --i) {
    int w = (x >> i) & 1;
    if (!trie[now][w]) trie[now][w] = ++tot;
    now = trie[now][w];
  }
}
long long ask(int x) {
  int now = 1;
  long long ans = 0;
  for (int i = 29; i >= 0; --i) {
    int w = (x >> i) & 1;
    if (trie[now][w])
      now = trie[now][w];
    else {
      ans += 1 << i;
      now = trie[now][w ^ 1];
    }
  }
  return ans;
}
long long work(int l, int r, int d) {
  if (l >= r) return 0;
  if (!(~d)) return 0;
  static int a[maxn], b[maxn];
  int t1 = 0, t2 = 0;
  for (int i = l; i <= r; ++i)
    if (A[i] & (1 << d))
      a[++t1] = A[i];
    else
      b[++t2] = A[i];
  for (int i = 1; i <= t2; ++i) A[l + i - 1] = b[i];
  for (int i = 1; i <= t1; ++i) A[l + t2 + i - 1] = a[i];
  long long ans = work(l, l + t2 - 1, d - 1) + work(l + t2, r, d - 1);
  if (!t1 || !t2) return ans;
  inittrie();
  long long tmp = (unsigned int)(-1) >> 1;
  for (int i = l; i <= r; ++i)
    if (A[i] & (1 << d)) ins(A[i]);
  for (int i = l; i <= r; ++i)
    if (!(A[i] & (1 << d))) tmp = min(tmp, ask(A[i]));
  return ans + tmp;
}
void solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &A[i]);
  long long ans = work(1, n, 29);
  printf("%I64d\n", ans);
  return;
}
int main() {
  solve();
  return 0;
}
