#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 44;
const long long INF = 1e17;
int n;
long long ans;
int val[M];
int getMid(int id, int li, int ri, int bas) {
  return lower_bound(val + li, val + ri, bas + (1 << id)) - val;
}
long long deal(int id, int li1, int ri1, int li2, int ri2, int bas1, int bas2) {
  if (li1 == ri1 || li2 == ri2) return INF;
  if (id == -1 || (val[li1] == val[ri1 - 1] && val[li2] == val[ri2 - 1]))
    return val[li1] ^ val[li2];
  int mid1 = getMid(id, li1, ri1, bas1), mid2 = getMid(id, li2, ri2, bas2);
  if ((mid1 == li1 && mid2 == li2) || (mid1 == li1 && mid2 == ri2) ||
      (mid1 == ri1 && mid2 == li2) || (mid1 == ri1 && mid2 == ri2))
    return deal(id - 1, li1, ri1, li2, ri2, bas1 + (mid1 == li1) * (1 << id),
                bas2 + (mid2 == li2) * (1 << id));
  return min(
      deal(id - 1, li1, mid1, li2, mid2, bas1, bas2),
      deal(id - 1, mid1, ri1, mid2, ri2, bas1 + (1 << id), bas2 + (1 << id)));
}
long long dfs(int id, int li, int ri, int bas) {
  if (id == -1) return 0;
  int mid = getMid(id, li, ri, bas);
  if (mid == li) return dfs(id - 1, li, ri, bas + (1 << id));
  if (mid == ri) return dfs(id - 1, li, ri, bas);
  return deal(id - 1, li, mid, mid, ri, bas, bas + (1 << id)) +
         dfs(id - 1, li, mid, bas) + dfs(id - 1, mid, ri, bas + (1 << id));
}
int main() {
  long long ans;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  sort(val + 1, val + n + 1);
  ans = dfs(30, 1, n + 1, 0);
  printf("%I64d", ans);
  return 0;
}
