#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
using Pa = pair<T, U>;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
template <class T, int MAX_LOG>
class BinaryTrie {
 private:
  BinaryTrie *ne[2];
  T lazy;
  int child_num;
  bool fill;
  void insert(const T &bit, int bit_id, int id) {
    propagate(bit_id);
    if (bit_id == -1) {
      child_num++;
    } else {
      auto &to = ne[(bit >> bit_id) & 1];
      if (!to) to = new BinaryTrie();
      to->insert(bit, bit_id - 1, id);
      child_num++;
    }
  }
  void insert(const T &bit, int id) { insert(bit, MAX_LOG, id); }
  void erase(const T &bit, int bit_id) {
    propagate(bit_id);
    if (bit_id == -1) {
      child_num--;
    } else {
      assert(ne[(bit >> bit_id) & 1]);
      ne[(bit >> bit_id) & 1]->erase(bit, bit_id - 1);
      child_num--;
    }
  }
  Pa<T, BinaryTrie *> max_element(const T &x, int bit_id) {
    propagate(bit_id);
    if (bit_id == -1) return {0, this};
    bool f = (x >> bit_id) & 1;
    f ^= 1;
    f ^= !(ne[f] && ne[f]->size());
    auto res = ne[f]->max_element(x, bit_id - 1);
    res.first |= T(f) << bit_id;
    return res;
  }
  Pa<T, BinaryTrie *> min_element(const T &x, int bit_id) {
    propagate(bit_id);
    if (bit_id == -1) return {0, this};
    bool f = (x >> bit_id) & 1;
    f ^= !(ne[f] && ne[f]->size());
    auto res = ne[f]->min_element(x, bit_id - 1);
    res.first |= T(f) << bit_id;
    return res;
  }
  ll count_less(const T &bit, int bit_index) {
    propagate(bit_index);
    if (bit_index == -1) return 0;
    int64_t ret = 0;
    if ((bit >> bit_index) & 1) {
      if (ne[0]) ret += ne[0]->size();
      if (ne[1]) ret += ne[1]->count_less(bit, bit_index - 1);
    } else {
      if (ne[0]) ret += ne[0]->count_less(bit, bit_index - 1);
    }
    return ret;
  }
  Pa<T, BinaryTrie *> kth_element(ll k, int bit_id) {
    propagate(bit_id);
    if (bit_id == -1) return {0, this};
    ll small = (ne[0] ? ne[0]->size() : 0);
    if (small < k) {
      auto res = ne[1]->kth_element(k - small, bit_id - 1);
      res.first |= T(1) << bit_id;
      return res;
    } else {
      return ne[0]->kth_element(k, bit_id - 1);
    }
  }

 public:
  BinaryTrie() : child_num(0), lazy(0), ne{nullptr, nullptr} {}
  void insert(const T &bit) { insert(bit, child_num); }
  void erase(const T &bit) { erase(bit, MAX_LOG); }
  pair<T, BinaryTrie *> max_element(const T x = 0) {
    assert(child_num);
    return max_element(x, MAX_LOG);
  }
  pair<T, BinaryTrie *> min_element(const T x = 0) {
    assert(child_num);
    return min_element(x, MAX_LOG);
  }
  ll count_less(const T &bit) { return count_less(bit, MAX_LOG); }
  pair<T, BinaryTrie *> kth_element(ll k) {
    assert(0 < k && k <= size());
    return kth_element(k, MAX_LOG);
  }
  int size() const { return child_num; }
  void xorpush(const T &bit) { lazy ^= bit; }
  void propagate(int bit_id) {
    if ((lazy >> bit_id) & 1) swap(ne[0], ne[1]);
    if (ne[0]) ne[0]->lazy ^= lazy;
    if (ne[1]) ne[1]->lazy ^= lazy;
    lazy = 0;
  }
};
vec<int> A(200000);
BinaryTrie<int, 30> trie;
ll ans = 0;
void rec(int l, int r, int k) {
  if (k == -1) return;
  if (r - l <= 1) return;
  if (r - l == 2) {
    ans += A[l] ^ A[r - 1];
    return;
  }
  sort(A.begin() + l, A.begin() + r);
  vec<int> v;
  int m = partition_point(A.begin() + l, A.begin() + r,
                          [&](int x) { return !(x >> k & 1); }) -
          A.begin();
  for (int i = l; i < r; i++)
    if (A[i] >> k & 1) {
      A[i] ^= 1 << k;
      v.push_back(i);
    }
  rec(l, m, k - 1);
  rec(m, r, k - 1);
  for (auto &i : v) A[i] ^= 1 << k;
  if (l == m || r == m) return;
  for (int i = l; i < m; i++) trie.insert(A[i]);
  int now = 2e9;
  for (int i = m; i < r; i++)
    now = min(now, A[i] ^ trie.min_element(A[i]).first);
  for (int i = l; i < m; i++) trie.erase(A[i]);
  ans += now;
  return;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  rec(0, N, 30);
  cout << ans << "\n";
}
