#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, K = 31;
int n, tot, ch[N * K][2], val[N];
long long ans;
void insert(int x) {
  int p = 0;
  for (int i = K - 1; i >= 0; i--) {
    int o = (x >> i) & 1;
    if (!ch[p][o]) ch[p][o] = ++tot;
    p = ch[p][o];
  }
}
int find(int x, int y, int dep) {
  if (dep < 0) return 0;
  int v0 = -1, v1 = -1;
  if (ch[x][0] && ch[y][0]) v0 = find(ch[x][0], ch[y][0], dep - 1);
  if (ch[x][1] && ch[y][1]) v1 = find(ch[x][1], ch[y][1], dep - 1);
  if (v0 != -1 && v1 != -1) return min(v0, v1);
  if (v0 != -1) return v0;
  if (v1 != -1) return v1;
  if (ch[x][0] && ch[y][1]) v0 = find(ch[x][0], ch[y][1], dep - 1) | (1 << dep);
  if (ch[x][1] && ch[y][0]) v1 = find(ch[x][1], ch[y][0], dep - 1) | (1 << dep);
  if (v0 != -1 && v1 != -1) return min(v0, v1);
  if (v0 != -1) return v0;
  if (v1 != -1) return v1;
}
void dfs(int x, int dep) {
  if (dep < 0) return;
  if (ch[x][0] && ch[x][1])
    ans += (long long)(find(ch[x][0], ch[x][1], dep - 1) | ((1 << dep)));
  if (ch[x][0]) dfs(ch[x][0], dep - 1);
  if (ch[x][1]) dfs(ch[x][1], dep - 1);
}
signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", val + i), insert(val[i]);
  dfs(0, K - 1);
  cout << ans << endl;
  return 0;
}
