#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30);
const int D = 29;
const int N = 6e6 + 10;
int a[D + 1], f[N][2];
long long ans;
int n, cnt, x;
void put(int x) {
  int now = 1;
  for (int i = D; i >= 0; i--, x >>= 1) a[i] = (x & 1);
  for (int i = 0; i <= D; i++)
    if (f[now][a[i]])
      now = f[now][a[i]];
    else
      now = f[now][a[i]] = ++cnt;
}
int merge(int x, int y, int d) {
  if (d == 0) return 0;
  int s = inf;
  if (f[x][0] && f[y][0]) s = min(s, merge(f[x][0], f[y][0], d - 1));
  if (f[x][1] && f[y][1]) s = min(s, merge(f[x][1], f[y][1], d - 1));
  if (s == inf) {
    s = (1 << (d - 1));
    if (f[x][0] && f[y][1])
      s += merge(f[x][0], f[y][1], d - 1);
    else if (f[x][1] && f[y][0])
      return s += merge(f[x][1], f[y][0], d - 1);
    return s;
  }
  return s;
}
void dfs(int now, int d) {
  if (f[now][0]) dfs(f[now][0], d - 1);
  if (f[now][1]) dfs(f[now][1], d - 1);
  if (f[now][0] && f[now][1])
    ans += (long long)(1 << (d - 1)) +
           (long long)merge(f[now][0], f[now][1], d - 1);
}
int main() {
  scanf("%d", &n);
  cnt = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    put(x);
  }
  dfs(1, D + 1);
  printf("%lld\n", ans);
}
