#include <bits/stdc++.h>
using namespace std;
int A[222222];
bool HasBit(int x, int b) { return ((x >> b) & 1); }
int Solve(int st, int en) {
  if (st == en) return 0;
  int msb;
  for (int b = 31; b >= 0; b--) {
    if (HasBit(A[en], b) && !HasBit(A[st], b)) {
      msb = b;
      break;
    }
  }
  int low = st;
  int high = en;
  while (low < high) {
    int mid = (low + high) / 2;
    if (HasBit(A[mid], msb)) {
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  return min(low - st - 1 + Solve(low, en), en - low + Solve(st, low - 1));
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> A[i];
  sort(A + 1, A + n + 1);
  cout << Solve(1, n) << endl;
}
