#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int64_t N = 2e5 + 55;
int64_t n;
int64_t arr[N];
int64_t tsz = 0;
int64_t dp[N * 30][2];
int64_t cntn[N * 30];
int64_t trie[N * 30][2];
void insert(int64_t x) {
  int64_t curr = 0;
  for (int64_t i = 29; i >= 0; --i) {
    int64_t bit = x >> i & 1;
    if (trie[curr][bit] == 0) {
      trie[curr][bit] = ++tsz;
    }
    curr = trie[curr][bit];
    cntn[curr]++;
  }
}
void load() {
  cin >> n;
  for (int64_t i = 0; i < n; ++i) {
    cin >> arr[i];
  }
}
void task() {
  for (int64_t i = 0; i < n; ++i) {
    insert(arr[i]);
  }
  for (int64_t i = tsz - 1; i >= 0; --i) {
    int64_t lch = trie[i][0];
    int64_t rch = trie[i][1];
    dp[i][0] = min(dp[lch][0] + dp[rch][1], dp[lch][1] + dp[rch][0]);
    dp[i][1] = cntn[i] - 1;
  }
  cout << dp[0][0] << '\n';
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t t = 1;
  while (t--) {
    load();
    task();
  }
  return 0;
}
