#include <bits/stdc++.h>
using namespace std;
const int maxi = 1e6 + 7;
const int inf = 0x3f3f3f3f;
int tree[6 * maxi][2], sz = 1, L[6 * maxi], R[6 * maxi];
long long a[maxi * 6];
void insert(long long x, long long num) {
  int c = 0;
  for (int i = 32; i >= 0; i--) {
    if (!tree[c][(x >> i) & 1]) tree[c][(x >> i) & 1] = sz++;
    c = tree[c][(x >> i) & 1];
    if (!L[c]) L[c] = num;
    R[c] = num;
  }
}
long long query(int p, int pos, long long x) {
  long long sum = 0;
  for (int i = pos; i >= 0; i--) {
    int c = (x >> i) & 1;
    if (tree[p][c])
      p = tree[p][c];
    else {
      p = tree[p][c ^ 1];
      sum += (1 << i);
    }
  }
  return sum;
}
long long divide(int p, int pos) {
  if (tree[p][0] && tree[p][1]) {
    int x = tree[p][0], y = tree[p][1];
    long long minn = inf;
    for (int i = L[x]; i <= R[x]; i++)
      minn = min(minn, query(y, pos - 1, a[i]) + (1 << pos));
    return minn + divide(tree[p][0], pos - 1) + divide(tree[p][1], pos - 1);
  } else if (tree[p][0])
    return divide(tree[p][0], pos - 1);
  else if (tree[p][1])
    return divide(tree[p][1], pos - 1);
  return 0;
}
int main() {
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) insert(a[i], i);
  printf("%lld\n", divide(0, 32));
  return 0;
}
