#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, trie[30 * N][2], trie_ind, freq[N * 30];
void add(int x) {
  int node = 0;
  for (int i = 29; i >= 0; i--) {
    int cur = (((1 << i) & x) != 0);
    if (!trie[node][cur]) trie[node][cur] = ++trie_ind;
    int nxt = trie[node][cur];
    node = nxt;
    freq[node]++;
  }
}
int solve(int node) {
  int x = trie[node][0], y = trie[node][1];
  if (!x && !y) return 0;
  if (!x) return solve(y);
  if (!y) return solve(x);
  int op1 = freq[x] - 1 + solve(y);
  int op2 = freq[y] - 1 + solve(x);
  return min(op1, op2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    add(x);
  }
  cout << solve(0);
}
