#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, cnt, a[N], nxt[N * 50][2];
long long ans;
void Add(int cur, int x) {
  for (int i = 30; ~i; i--) {
    if (!nxt[cur][x >> i & 1]) nxt[cur][x >> i & 1] = ++cnt;
    cur = nxt[cur][x >> i & 1];
  }
}
int Query(int cur, int x) {
  int ret = 0;
  for (int i = 30; ~i; i--) {
    if (nxt[cur][x >> i & 1])
      cur = nxt[cur][x >> i & 1];
    else
      ret += 1 << i, cur = nxt[cur][~x >> i & 1];
  }
  return ret;
}
int lc;
inline bool cmp(const int &a, const int &b) {
  return (a >> lc & 1) < (b >> lc & 1);
}
int Merge(int x, int y) {
  if (!x || !y) return x + y;
  nxt[x][0] = Merge(nxt[x][0], nxt[y][0]);
  nxt[x][1] = Merge(nxt[x][1], nxt[y][1]);
  return x;
}
int solve(int l, int r, int t) {
  if (!t) {
    int ro = ++cnt;
    Add(ro, a[l]);
    return ro;
  }
  lc = t - 1;
  sort(a + l, a + 1 + r, cmp);
  int mid = l - 1;
  for (int i = l; i <= r; i++)
    if (a[i] >> lc & 1)
      break;
    else
      mid = i;
  int lro = 0, rro = 0, cur = 1 << 30;
  if (l <= mid) lro = solve(l, mid, t - 1);
  if (mid + 1 <= r) rro = solve(mid + 1, r, t - 1);
  for (int i = l; i <= mid; i++) cur = min(cur, Query(rro, a[i]));
  if (mid < l || mid >= r) cur = 0;
  ans += cur;
  return Merge(lro, rro);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  solve(1, n, 31);
  cout << ans << endl;
  return 0;
}
