#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
char buf[1 << 23], *p1 = buf, *p2 = buf;
int a[N], b[N], n, rt[N], c[N * 33][2], sz[N * 33], cl;
int read() {
  int res = 0, fl = 0;
  char a =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
           ? EOF
           : *p1++);
  while (a < '0' || a > '9')
    fl |= a == '-',
        a = (p1 == p2 &&
                     (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
                 ? EOF
                 : *p1++);
  while (a >= '0' && a <= '9')
    res = res * 10 + a - '0',
    a = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  return fl ? -res : res;
}
void ins(int &o1, int o2, int x, int st = 29) {
  o1 = ++cl, sz[o1] = sz[o2] + 1;
  if (st < 0) return;
  int lp = x >> st & 1;
  c[o1][lp ^ 1] = c[o2][lp ^ 1], ins(c[o1][lp], c[o2][lp], x, st - 1);
}
long long query(int o1, int o2, int x, int st = 29) {
  if (st < 0) return 0;
  int lp = x >> st & 1;
  if (sz[c[o1][lp]] - sz[c[o2][lp]])
    return query(c[o1][lp], c[o2][lp], x, st - 1);
  return query(c[o1][lp ^ 1], c[o2][lp ^ 1], x, st - 1) + (1 << st);
}
long long sol(int l, int r) {
  if (l == r) return 0;
  long long i, j = 0, res = 2e9;
  for (i = 29; ~i; i--)
    if ((a[r] >> i & 1) && (a[l] >> i & 1))
      j += 1 << i;
    else if ((a[r] >> i & 1) ^ (a[l] >> i & 1))
      break;
  if (j)
    for (i = l; i <= r; i++) a[i] ^= j;
  if (!a[r]) return 0;
  for (i = 29; ~i; i--)
    if (a[r] >> i & 1) {
      j = 1 << i;
      break;
    }
  int lp = lower_bound(a + l, a + r + 1, j) - a, la = rt[lp - 1],
      lb = rt[l - 1], lc = rt[r], st;
  for (i = 29; ~i; i--)
    if ((b[r] >> i & 1) ^ (b[l] >> i & 1))
      break;
    else
      la = c[la][b[l] >> i & 1], lb = c[lb][b[l] >> i & 1],
      lc = c[lc][b[l] >> i & 1];
  if (r - lp <= lp - l)
    for (st = i, i = lp; i <= r; i++) res = min(res, query(la, lb, b[i], st));
  else
    for (st = i, i = l; i < lp; i++) res = min(res, query(lc, la, b[i], st));
  return sol(l, lp - 1) + sol(lp, r) + res;
}
int main() {
  int i, j;
  for (n = read(), i = 1; i <= n; i++) a[i] = read();
  sort(a + 1, a + n + 1), memcpy(b, a, sizeof(b));
  for (i = 1; i <= n; i++) ins(rt[i], rt[i - 1], a[i]);
  cout << sol(1, n);
  return 0;
}
