#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
int solve(int l, int r, int bit) {
  if (l >= r) return 1e9;
  if (r - l <= 2) return 0;
  int mid = r;
  for (int i = l; i < r - 1; ++i) {
    if ((a[i] & (1 << bit)) != (a[i + 1] & (1 << bit))) mid = i + 1;
  }
  int left = solve(l, mid, bit - 1) + max(0, r - mid - 1);
  int right = solve(mid, r, bit - 1) + (mid - l - 1);
  return min(left, right);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);
  cout << solve(0, n, 30) << endl;
  return 0;
}
