#include <bits/stdc++.h>
int faster_in() {
  int r = 0, c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') return -faster_in();
  for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar())
    ;
  return r;
}
using namespace std;
const int INF = 1234567890;
struct node {
  int sz;
  int dp;
  int children[2] = {-1, -1};
};
vector<node> trie;
int root = 0;
void _insert(vector<int> &a) {
  int v = root;
  trie[v].sz++;
  for (int x : a) {
    if (trie[v].children[x] == -1) {
      trie[v].children[x] = trie.size();
      trie.push_back(node());
      trie.back().sz = 0;
    }
    v = trie[v].children[x];
    trie[v].sz++;
  }
}
int f(int v) {
  if (trie[v].sz == 1) return 0;
  int L = 0, R = 0;
  if (trie[v].children[0] != -1) L = trie[trie[v].children[0]].sz;
  if (trie[v].children[1] != -1) R = trie[trie[v].children[1]].sz;
  if (L + R == 0) return 0;
  if (L <= 1) return f(trie[v].children[1]);
  if (R <= 1) return f(trie[v].children[0]);
  int res = INF;
  res = min(res, L - 1 + f(trie[v].children[1]));
  res = min(res, R - 1 + f(trie[v].children[0]));
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  trie.push_back(node());
  trie[root].sz = 0;
  trie[root].dp = INF;
  int n;
  cin >> n;
  int a[n];
  for (int i = (int)0; i < (int)n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = (int)0; i < (int)n; ++i) {
    int x = a[i];
    vector<int> v;
    for (int m = 0; (1LL << m) <= (long long)1e9; m++) {
      if ((x >> m) & 1)
        v.push_back(1);
      else
        v.push_back(0);
    }
    reverse((v).begin(), (v).end());
    _insert(v);
  }
  cout << f(root) << '\n';
  return 0;
}
