#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
  int si = 1;
  char c = getchar();
  x = 0;
  while (!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
  while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
  x *= si;
}
template <typename T, typename... Args>
inline void read(T& x, Args&... args) {
  read(x);
  read(args...);
}
const int mxk = 1e6 + 7;
int n, a[mxk], ans = 0;
int tr[mxk << 2][2], l[mxk << 2], r[mxk << 2], cnt = 1;
void insert(int v, int idx) {
  int cur = 1;
  for (int i = 30; i >= 0; --i) {
    bool x = v & (1 << i);
    l[cur] = std::min(l[cur], idx);
    r[cur] = std::max(r[cur], idx);
    if (!tr[cur][x]) tr[cur][x] = ++cnt;
    cur = tr[cur][x];
  }
  l[cur] = r[cur] = idx;
}
int query(int cur, int v, int b) {
  int ret = 0;
  for (int i = b; i >= 0; --i) {
    bool x = v & (1 << i);
    if (!tr[cur][x])
      cur = tr[cur][x ^ 1], ret = ret | (1 << i);
    else
      cur = tr[cur][x];
  }
  return ret;
}
long long dfs(int cur, int dep) {
  if (dep < 0 || (!cur)) return 0;
  long long ret = 0;
  if (tr[cur][0] && tr[cur][1]) {
    int tmp = (1 << 30);
    for (int i = l[tr[cur][1]]; i <= r[tr[cur][1]]; ++i)
      tmp = min(tmp, query(tr[cur][0], a[i], dep - 1));
    ret += tmp | (1 << dep);
  }
  ret += dfs(tr[cur][0], dep - 1);
  ret += dfs(tr[cur][1], dep - 1);
  return ret;
}
int main() {
  memset(l, 0x3f, sizeof(l));
  memset(r, 0, sizeof(r));
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) insert(a[i], i);
  cout << dfs(1, 30) << endl;
  return 0;
}
