#include <bits/stdc++.h>
using namespace std;
void swap(int &a, int &b) {
  int temp = a;
  a = b;
  b = temp;
}
void findAns(int s, int e, int ms, int r, int &ans, int a[]) {
  if (e - s <= 0 || !ms) {
    ans = min(r, ans);
    return;
  }
  int mid = e + 1;
  for (int i = e; i >= s; i--) {
    if (!(a[i] & ms)) {
      break;
    }
    mid--;
  }
  findAns(s, mid - 1, ms >> 1, r + max(0, e - mid), ans, a);
  findAns(mid, e, ms >> 1, r + max(0, mid - s - 1), ans, a);
}
long long solve() {
  int n, x = 1;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int ans = max(0, n - 2);
  x <<= 30;
  findAns(0, n - 1, x, 0, ans, a);
  cout << ans;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ifstream in("input.txt");
  ofstream out("output.txt");
  solve();
  return 0;
}
