#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7, maxm = 35 * maxn;
int nxt[maxm][2], tot, a[maxn];
long long ans = 0;
void ins(int x) {
  int now = 0;
  for (int i = 29; i >= 0; i--) {
    int go = (x >> i) & 1;
    if (nxt[now][go] == 0) nxt[now][go] = ++tot;
    now = nxt[now][go];
  }
}
long long query(int x) {
  long long ret = 0;
  int now = 0;
  for (int i = 29; i >= 0; i--) {
    int go = (x >> i) & 1;
    if (nxt[now][go])
      now = nxt[now][go];
    else
      now = nxt[now][go ^ 1], ret |= (1 << i);
  }
  return ret;
}
void dfs(int l, int r, int dep) {
  if (dep == -1 || l >= r) return;
  int mid = l - 1;
  while (mid < r && (a[mid + 1] >> dep & 1) == 0) mid++;
  dfs(l, mid, dep - 1);
  dfs(mid + 1, r, dep - 1);
  if (mid == l - 1 || mid == r) return;
  for (int i = l; i <= mid; i++) ins(a[i]);
  long long ret = 1e18;
  for (int i = mid + 1; i <= r; i++) ret = min(ret, query(a[i]));
  ans += ret;
  for (int i = 0; i <= tot; i++) nxt[i][0] = nxt[i][1] = 0;
  tot = 0;
}
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  dfs(1, n, 29);
  return 0 * printf("%lld\n", ans);
}
