#include <bits/stdc++.h>
using namespace std;
int a[200005], n, tr[200005 * 30][2], cnt[200005 * 30], num;
inline void insert(int x) {
  int p = 0;
  for (int i = 30; i >= 0; --i) {
    int v = 0;
    if (x & (1 << i)) v = 1;
    if (!tr[p][v]) tr[p][v] = ++num;
    p = tr[p][v];
    ++cnt[p];
  }
}
const int INF = 1e9;
inline int solve(int p) {
  int ans1 = INF, ans2 = INF;
  if (tr[p][0]) ans1 = solve(tr[p][0]) + max(0, cnt[p] - cnt[tr[p][0]] - 1);
  if (tr[p][1]) ans2 = solve(tr[p][1]) + max(0, cnt[p] - cnt[tr[p][1]] - 1);
  if (ans1 == INF && ans2 == INF) return 0;
  return min(ans1, ans2);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    insert(a[i]);
  }
  cnt[0] = n;
  printf("%d\n", solve(0));
  return 0;
}
