#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int a[200500], t[200500 * 33][2], n, tot;
long long ans = 0;
void add(int &x, int val, int d) {
  if (!x) x = ++tot;
  if (d == -1) return;
  if ((val >> d) & 1)
    add(t[x][1], val, d - 1);
  else
    add(t[x][0], val, d - 1);
}
int ask(int x, int val, int d) {
  if (d == -1) return 0;
  int p = (val >> d) & 1;
  if (t[x][p])
    return ask(t[x][p], val, d - 1);
  else
    return (1 << d) + ask(t[x][p ^ 1], val, d - 1);
}
void solve(int l, int r, int L, int R) {
  if (l >= r) return;
  if (L > R) return;
  int mid = (l + r) / 2;
  int w = R + 1;
  for (int i = L; i <= R; i++)
    if (a[i] > mid) {
      w = i;
      break;
    }
  if (L < w && w <= R) {
    int rt = 1;
    tot = 1;
    for (int i = L; i <= w - 1; i++) add(rt = 1, a[i], 29);
    int mn = 2e9;
    for (int i = w; i <= R; i++) mn = min(mn, ask(rt = 1, a[i], 29));
    ans += 1ll * mn;
    for (int i = 1; i <= tot; i++) t[i][0] = t[i][1] = 0;
  }
  solve(l, mid, L, w - 1);
  solve(mid + 1, r, w, R);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  sort(a + 1, a + 1 + n);
  solve(0, (1 << 30) - 1, 1, n);
  printf("%lld\n", ans);
  return 0;
}
