#include <bits/stdc++.h>
using namespace std;
int a[200005], n;
int f(int x, int l, int r) {
  if (l == r) return 0;
  int index =
      lower_bound(a + l, a + r + 1, ((a[l] >> (x + 1)) << (x + 1)) + (1 << x)) -
      a;
  if (index == l || index == l + 1)
    return f(x - 1, index, r);
  else if (index == r || index == r + 1)
    return f(x - 1, l, index - 1);
  else
    return min(f(x - 1, index, r) + index - l - 1,
               f(x - 1, l, index - 1) + r - index);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  cout << f(29, 1, n);
  return 0;
}
