#include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
long long n;
long long a[N];
long long ans;
long long ch[30 * N][2];
long long cnt = 1;
void insert(long long ind, long long val, long long d) {
  if (d < 0) return;
  bool v = val & (1 << d);
  if (!ch[ind][v]) {
    ch[ind][v] = cnt;
    cnt++;
  }
  insert(ch[ind][v], val, d - 1);
}
void clear() {
  for (long long i = 0; i < cnt; i++) ch[i][0] = ch[i][1] = 0;
  cnt = 1;
}
long long check(long long ind, long long val) {
  long long ret = 0;
  for (long long i = 30 - 1; i >= 0; i--) {
    bool v = val & (1 << i);
    if (ch[ind][v])
      ind = ch[ind][v];
    else {
      ind = ch[ind][!v];
      ret += (1 << i);
    }
  }
  return ret;
}
void work(long long l, long long r, long long d) {
  if (d < 0 || l >= r) return;
  long long mask = (a[l] >> (d + 1)) << (d + 1);
  long long mid = lower_bound(&a[l], &a[r], mask | (1 << d)) - a;
  work(l, mid, d - 1);
  work(mid, r, d - 1);
  if (mid == l || mid == r) {
    return;
  }
  clear();
  for (long long i = l; i < mid; i++) {
    insert(0, a[i], 29);
  }
  long long mn = (long long)(1e12);
  for (long long i = mid; i < r; i++) {
    mn = min(mn, check(0, a[i]));
  }
  ans += mn;
}
void solve() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(&a[0], &a[n]);
  work(0, n, 29);
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
