#include <bits/stdc++.h>
using namespace std;
struct Trie {
  vector<int> left;
  vector<int> right;
  Trie() {
    left.push_back(0);
    right.push_back(0);
  }
  int node() {
    left.push_back(0);
    right.push_back(0);
    return int(left.size()) - 1;
  }
  void add(int x, int bit) {
    int n = 0;
    for (int k = bit; k >= 0; --k) {
      if (x & (1 << k)) {
        if (!left[n]) {
          int idx = node();
          left[n] = idx;
        }
        n = left[n];
      } else {
        if (!right[n]) {
          int idx = node();
          right[n] = idx;
        }
        n = right[n];
      }
    }
  }
  int get(int x, int bit) {
    int n = 0;
    int res = 0;
    for (int k = bit; k >= 0; --k) {
      if (x & (1 << k)) {
        if (left[n])
          n = left[n];
        else {
          n = right[n];
          res |= 1 << k;
        }
      } else {
        if (right[n])
          n = right[n];
        else {
          n = left[n];
          res |= 1 << k;
        }
      }
    }
    return res;
  }
};
const int nmax = 2e5 + 5;
int v[nmax];
long long ans = 0;
int n;
void solve(int l, int r, int bit) {
  if (l > r) return;
  if (bit < 0) return;
  int m = l;
  while (m <= r && !((1 << bit) & v[m])) m++;
  solve(l, m - 1, bit - 1);
  solve(m, r, bit - 1);
  if (m == l) return;
  if (m == r + 1) return;
  Trie t;
  for (int i = l; i <= m - 1; i++) {
    t.add(v[i], bit);
  }
  int tmp = 1 << 30;
  for (int i = m; i <= r; i++) {
    tmp = min(tmp, t.get(v[i], bit));
  }
  ans += tmp;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> v[i];
  sort(v + 1, v + n + 1);
  solve(1, n, 29);
  cout << ans << '\n';
  return 0;
}
