#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
struct node {
  int idx, cnt;
  int child[2];
  node() {
    idx = -1, cnt = 0;
    memset((child), -1, sizeof(child));
    ;
  }
};
vector<node> trie;
int init() {
  node x;
  trie.push_back(x);
  return (int)trie.size() - 1;
}
void add(int n, int s, int i, int idx_) {
  trie[n].cnt++;
  if (i == -1) {
    trie[n].idx = idx_;
    return;
  }
  int c = s & (1 << i);
  if (c) c = 1;
  if (trie[n].child[c] == -1) {
    int next = init();
    trie[n].child[c] = next;
  }
  add(trie[n].child[c], s, i - 1, idx_);
}
void remove(int n, int s, int i) {
  trie[n].cnt--;
  if (i == -1) return;
  int c = s & (1 << i);
  if (c) c = 1;
  remove(trie[n].child[c], s, i - 1);
}
int query(int n, int s, int i) {
  if (i == -1) return trie[n].idx;
  int c = s & (1 << i);
  if (c) c = 1;
  if (trie[n].child[c] != -1 && trie[trie[n].child[c]].cnt > 0)
    return query(trie[n].child[c], s, i - 1);
  else
    return query(trie[n].child[1 - c], s, i - 1);
}
int a[200000];
int parent[200000];
int find(int a) {
  if (parent[a] < 0) return a;
  return parent[a] = find(parent[a]);
}
void merge(int a, int b) {
  a = find(a), b = find(b);
  if (a != b) {
    parent[a] += parent[b];
    parent[b] = a;
  }
}
int main() {
  memset((parent), -1, sizeof(parent));
  ;
  int n;
  scanf("%d", &n);
  init();
  for (int(i) = (0); (i) <= (n - 1); (i) += (1)) scanf("%d", a + i);
  sort(a, a + n);
  n = unique(a, a + n) - a;
  for (int(i) = (0); (i) <= (n - 1); (i) += (1)) add(0, a[i], 29, i);
  long long ans = 0;
  while (1) {
    map<int, vector<int> > M;
    for (int(i) = (0); (i) <= (n - 1); (i) += (1)) M[find(i)].push_back(i);
    if (M.size() == 1) break;
    for (auto it = M.begin(); it != M.end(); it++) {
      vector<int> &v = it->second;
      for (int x : v) remove(0, a[x], 29);
      int mn = 1 << 30, what = -1;
      for (int x : v) {
        int i = query(0, a[x], 29);
        int res = a[i] ^ a[x];
        if (res < mn) what = i, mn = res;
      }
      if (find(what) != find(it->first)) {
        ans += mn;
        merge(what, it->first);
      }
      for (int x : v) add(0, a[x], 29, x);
    }
  }
  printf("%lld", ans);
}
