#include <bits/stdc++.h>
#pragma GCC optimize(2)
long long read() {
  long long x = 0;
  long long f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
using namespace std;
const int maxn = 8e6 + 100;
const long long INF = 1e17;
int cnt = 0;
int a[maxn];
int t[maxn][2];
int L[maxn], R[maxn];
void Insert(long long x, int id) {
  int rt = 0;
  for (int k = 32; k >= 0; k--) {
    int op = (x >> k & 1ll) ? 1 : 0;
    if (!t[rt][op]) t[rt][op] = ++cnt;
    rt = t[rt][op];
    if (!L[rt]) L[rt] = id;
    R[rt] = id;
  }
}
long long AnswerPos(int rt, int pos, long long x) {
  long long ans = 0;
  for (int i = pos; i >= 0; i--) {
    int op = (x >> i & 1ll) ? 1 : 0;
    if (t[rt][op])
      rt = t[rt][op];
    else {
      rt = t[rt][!op];
      ans += (1ll << i);
    }
  }
  return ans;
}
void Traceback(int rt) {
  printf("%d %d\n", L[rt], R[rt]);
  if (t[rt][0]) Traceback(t[rt][0]);
  if (t[rt][1]) Traceback(t[rt][1]);
}
long long Divide(int rt, int pos) {
  if (t[rt][0] && t[rt][1]) {
    int x = t[rt][0], y = t[rt][1];
    long long minl = INF;
    for (int k = L[x]; k <= R[x]; k++)
      minl = min(minl, AnswerPos(y, pos - 1, a[k]) + (1ll << pos));
    return minl + Divide(t[rt][0], pos - 1) + Divide(t[rt][1], pos - 1);
  } else if (t[rt][0])
    return Divide(t[rt][0], pos - 1);
  else if (t[rt][1])
    return Divide(t[rt][1], pos - 1);
  return 0;
}
int main() {
  int n;
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  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;
}
