#include <bits/stdc++.h>
using namespace std;
int a[200005];
bool bits[31];
long long ans = 0, res = 0;
struct trie {
  trie* nt[2];
  int s[2], e[2];
  trie() {
    nt[0] = nt[1] = NULL;
    s[0] = e[0] = s[1] = e[1] = 0;
  }
};
trie* root = new trie();
void query2(trie* cur, int h, int v) {
  if (h == -1) return;
  int b = (v >> h) & 1;
  if (cur->nt[b] == NULL) b = 1 - b, res += (1 << h);
  query2(cur->nt[b], h - 1, v);
}
void query1(trie* cur, int h) {
  if (h == -1) return;
  int sz0 = 0, sz1 = 0;
  if (cur->nt[0] != NULL) sz0 = cur->e[0] - cur->s[0] + 1;
  if (cur->nt[1] != NULL) sz1 = cur->e[1] - cur->s[1] + 1;
  if (sz0 != 0 && sz1 != 0) {
    if (sz0 < sz1) {
      long long mn = 1e18;
      for (int i = cur->s[0]; i <= cur->e[0]; i++)
        res = 0, query2(cur->nt[1], h - 1, a[i]), mn = min(mn, res);
      ans += mn + (1 << h);
    } else {
      long long mn = 1e18;
      for (int i = cur->s[1]; i <= cur->e[1]; i++)
        res = 0, query2(cur->nt[0], h - 1, a[i]), mn = min(mn, res);
      ans += mn + (1 << h);
    }
  }
  if (sz0 != 0) query1(cur->nt[0], h - 1);
  if (sz1 != 0) query1(cur->nt[1], h - 1);
}
void insert(trie* cur, int h, int idx) {
  if (h == -1) return;
  int b = bits[h];
  if (cur->nt[b] == NULL) cur->nt[b] = new trie();
  if (cur->s[b] == 0) cur->s[b] = idx;
  cur->e[b] = idx;
  insert(cur->nt[b], h - 1, idx);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    int x = a[i];
    memset(bits, 0, sizeof(bits));
    int j = 0;
    while (x) {
      bits[j++] = x % 2;
      x /= 2;
    }
    insert(root, 30, i);
  }
  query1(root, 30);
  printf("%lld\n", ans);
}
