#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int aa[N];
int solve(int l, int r, int b) {
  if (b == -1) return 0;
  int i = l;
  while (i < r && !(aa[i] & 1 << b)) i++;
  if (i == l || i == r) return solve(l, r, b - 1);
  return min(solve(l, i, b - 1) + r - i - 1, solve(i, r, b - 1) + i - l - 1);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> aa[i];
  sort(aa, aa + n);
  cout << solve(0, n, 29) << '\n';
  return 0;
}
