#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int ch[N * 32][2], n, tot, a[N], val[N * 32];
long long ans;
void insert(int x) {
  int p = 0;
  bool d;
  for (int i = 30; i >= 0; i--) {
    d = (x >> i) & 1;
    if (!ch[p][d]) ch[p][d] = ++tot;
    p = ch[p][d];
    val[p]++;
  }
}
int getval(int p, int d, int x) {
  int r = 0;
  bool b;
  for (int i = d; i >= 0; i--) {
    r <<= 1;
    b = (x >> i) & 1;
    if (ch[p][b])
      p = ch[p][b];
    else
      p = ch[p][b ^ 1], r |= 1;
  }
  return r;
}
void checkmin(int &x, int y) {
  if (x > y) x = y;
}
void solve(int p, int l, int r, int d) {
  if (ch[p][0] == 0 && ch[p][1] == 0) return;
  if (!ch[p][0])
    solve(ch[p][1], l, r, d - 1);
  else if (!ch[p][1])
    solve(ch[p][0], l, r, d - 1);
  else {
    int mid = l + val[ch[p][0]] - 1;
    solve(ch[p][0], l, mid, d - 1);
    solve(ch[p][1], mid + 1, r, d - 1);
    int now = 0x7fffffff;
    for (int i = l; i <= mid; i++) {
      checkmin(now, getval(ch[p][1], d - 1, a[i]) | (1 << d));
    }
    ans += (long long)now;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  n = unique(a + 1, a + n + 1) - a - 1;
  for (int i = 1; i <= n; i++) insert(a[i]);
  solve(0, 1, n, 30);
  printf("%lld\n", ans);
}
