#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
int n, a[N];
int par[N], endNode[N];
vector<int> comp[N];
int check[N], vis[30 * N];
ll ans;
int find(int i) {
  if (par[i] == i) {
    return i;
  } else {
    return par[i] = find(par[i]);
  }
}
int nNode;
struct node {
  int child[2], size;
} trie[30 * N];
vector<int> inDex[30 * N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    int now = 0;
    for (int j = 29; j >= 0; j--) {
      int x = ((a[i] >> j) & 1);
      if (trie[now].child[x] == 0) {
        trie[now].child[x] = ++nNode;
      }
      now = trie[now].child[x];
      trie[now].size++;
    }
    inDex[now].push_back(i);
    endNode[i] = now;
  }
  for (int i = 1; i <= n; i++) par[i] = i;
  while (1) {
    for (int i = 1; i <= n; i++) comp[i].clear();
    for (int i = 1; i <= n; i++) {
      int p = find(i);
      comp[p].push_back(i);
    }
    int cntComp = 0;
    for (int i = 1; i <= n; i++)
      if (comp[i].size() > 0) cntComp++;
    if (cntComp == 1) break;
    for (int i = 1; i <= n; i++) {
      if (comp[i].size() == 0) continue;
      for (int j : comp[i]) {
        int now = 0;
        for (int bit = 29; bit >= 0; bit--) {
          int x = ((a[j] >> bit) & 1);
          now = trie[now].child[x];
          trie[now].size--;
        }
      }
      int u, v, mn = 1e9;
      for (int j : comp[i]) {
        int now = 0, res = 0;
        for (int bit = 29; bit >= 0; bit--) {
          int x = ((a[j] >> bit) & 1);
          if (trie[now].child[x] > 0 && trie[trie[now].child[x]].size > 0) {
            now = trie[now].child[x];
          } else {
            res += (1 << bit);
            now = trie[now].child[x ^ 1];
          }
        }
        if (res < mn) {
          mn = res;
          u = j;
          v = (inDex[now][0] != i ? inDex[now][0] : inDex[now][1]);
        }
      }
      int paru = find(u), parv = find(v);
      if (paru != parv) {
        ans += mn;
        par[paru] = parv;
      }
      for (int j : comp[i]) {
        int now = 0;
        for (int bit = 29; bit >= 0; bit--) {
          int x = ((a[j] >> bit) & 1);
          now = trie[now].child[x];
          trie[now].size++;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (vis[endNode[i]] == 1) continue;
      vector<int> newId;
      for (int j : inDex[endNode[i]]) {
        int p = find(j);
        if (check[p] == 0) {
          newId.push_back(p);
          check[p] = 1;
        }
      }
      inDex[endNode[i]] = newId;
      for (int j : newId) check[j] = 0;
      vis[endNode[i]] = 1;
    }
  }
  cout << ans;
}
