#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxN = 2e5;
int a[mxN];
int lb(int l, int r, int msb) {
  while (l != r) {
    int m = (l + r) >> 1;
    (a[m] & msb) ? r = m : l = m + 1;
  }
  return l;
}
int min_xor(int l1, int r1, int l2, int r2, int msb) {
  if (l1 == r1 || l2 == r2) return 1 << 30;
  if (!msb) return 0;
  int m1 = lb(l1, r1, msb), m2 = lb(l2, r2, msb);
  if (l1 == m1 && m2 == r2 || m1 == r1 && l2 == m2)
    return min_xor(l1, r1, l2, r2, msb >> 1) + msb;
  return min(min_xor(l1, m1, l2, m2, msb >> 1),
             min_xor(m1, r1, m2, r2, msb >> 1));
}
ll mst(int l, int r, int msb) {
  if (!msb || r - l <= 1) return 0;
  int m = lb(l, r, msb);
  ll ret = mst(l, m, msb >> 1) + mst(m, r, msb >> 1);
  if (l != m && m != r) ret += min_xor(l, m, m, r, msb >> 1) + msb;
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> a[i];
  sort(a, a + N);
  cout << mst(0, N, 1 << 29);
}
