#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char now[1 << 16], *S, *T;
  if (T == S) {
    T = (S = now) + fread(now, 1, 1 << 16, stdin);
    if (T == S) return EOF;
  }
  return *S++;
}
inline long long read() {
  register long long x = 0, f = 1;
  char ch = gc();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = gc();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = gc();
  }
  return (f == 1) ? x : -x;
}
struct node {
  long long son[2];
} g[6200001];
long long cnt;
void insert(long long T, long long &rt, long long w) {
  if (!rt) rt = ++cnt;
  if (T == -1) return;
  long long op = (w >> T) & 1LL;
  insert(T - 1, g[rt].son[op], w);
}
long long query(long long T, long long rt, long long w) {
  if (T == -1) return 0;
  long long op = (w >> T) & 1LL;
  if (g[rt].son[op])
    return query(T - 1, g[rt].son[op], w);
  else
    return query(T - 1, g[rt].son[op ^ 1], w) + (1 << T);
}
long long solve(const vector<long long> &now, long long rt, long long T) {
  if (!rt) return 0;
  long long len = now.size();
  vector<long long> D[2];
  for (long long i = 0; i < len; i++) {
    D[(now[i] >> T) & 1].push_back(now[i]);
  }
  if ((long long)D[0].size() == 0) return solve(D[1], g[rt].son[1], T - 1);
  if ((long long)D[1].size() == 0) return solve(D[0], g[rt].son[0], T - 1);
  len = D[1].size();
  long long rem = (1LL << 31LL);
  for (long long i = 0; i < len; i++)
    rem = min(rem, (1LL << T) + query(T - 1, g[rt].son[0], D[1][i]));
  return rem + solve(D[0], g[rt].son[0], T - 1) +
         solve(D[1], g[rt].son[1], T - 1);
}
signed main() {
  vector<long long> sb;
  sb.clear();
  long long n = read(), root = 0;
  for (long long i = 1; i <= n; i++) sb.push_back(read());
  for (long long i = 0; i < n; i++) insert(31, root, sb[i]);
  printf("%lld\n", solve(sb, root, 31));
  return 0;
}
