#include <bits/stdc++.h>
const int MAXN = 2e5 + 10;
const double eps = 1e-8;
const int mod = 1e9 + 9;
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 f[MAXN], n, a[MAXN];
vector<int> vec[MAXN];
int rt, cnt;
typedef struct node {
  int ch[2];
  int sum;
} node;
node d[MAXN * 31];
vector<int> v[MAXN * 31];
void newnode(int &x) {
  x = ++cnt;
  d[x].ch[0] = d[x].ch[1] = 0;
  d[x].sum = 0;
}
void insert(int x, int id) {
  int temp = rt;
  for (int i = 29; i >= 0; i--) {
    int t = ((x >> i) & 1);
    if (!d[temp].ch[t]) newnode(d[temp].ch[t]);
    temp = d[temp].ch[t];
    d[temp].sum++;
  }
  if (id) v[temp].push_back(id);
}
void erase(int x) {
  int temp = rt;
  for (int i = 29; i >= 0; i--) {
    int t = ((x >> i) & 1);
    temp = d[temp].ch[t];
    d[temp].sum--;
  }
}
int find1(int x) {
  if (x == f[x])
    return x;
  else
    return f[x] = find1(f[x]);
}
int pos, minn;
pair<int, int> query(int x) {
  int temp = rt;
  int ans = 0;
  for (int i = 29; i >= 0; i--) {
    int t = ((x >> i) & 1);
    if (d[d[temp].ch[t]].sum > 0) {
      temp = d[temp].ch[t];
    } else {
      ans += (1 << i), temp = d[temp].ch[t ^ 1];
      if (ans > minn) {
        ans = (1 << 30);
        break;
      }
    }
  }
  pair<int, int> dp;
  dp.first = ans;
  if (dp.first == (1 << 30))
    dp.second = -1;
  else
    dp.second = v[temp][0];
  return dp;
}
int p[MAXN];
typedef struct Node {
  int k, x, y;
  friend bool operator<(Node aa, Node bb) { return aa.k < bb.k; }
} Node;
Node M[MAXN];
int main() {
  n = read();
  newnode(rt);
  for (int i = 1; i <= n; i++) a[i] = read(), insert(a[i], i), f[i] = i;
  long long ans1 = 0;
  int tot;
  while (1) {
    int num = 0;
    for (int i = 1; i <= n; i++)
      if (find1(i) == i) num++, vec[num].push_back(i), p[i] = num;
    for (int i = 1; i <= n; i++)
      if (find1(i) != i) vec[p[find1(i)]].push_back(i), p[i] = p[find1(i)];
    if (num == 1) break;
    tot = 0;
    for (int i = 1; i <= num; i++) {
      minn = (1 << 30);
      for (int j = 0; j < vec[i].size(); j++) erase(a[vec[i][j]]);
      for (int j = 0; j < vec[i].size(); j++) {
        pair<int, int> ans = query(a[vec[i][j]]);
        if (ans.first < minn) minn = ans.first, pos = ans.second;
      }
      M[++tot] = (Node){minn, vec[i][0], pos};
      for (int j = 0; j < vec[i].size(); j++) {
        insert(a[vec[i][j]], 0);
      }
    }
    sort(M + 1, M + tot + 1);
    for (int i = 1; i <= tot; i++) {
      int t1 = p[M[i].x];
      int t2 = p[M[i].y];
      int x = find1(vec[t1][0]);
      int y = find1(vec[t2][0]);
      if (x == y) continue;
      f[x] = y;
      ans1 += M[i].k;
      num--;
    }
    if (num == 1) break;
    for (int i = 1; i <= num; i++) vec[i].clear();
  }
  printf("%lld\n", ans1);
  return 0;
}
