#include <bits/stdc++.h>
using namespace std;
int tree[5000005][2], siz[5000005], tot, ans;
void insert(int x) {
  int u = 0;
  for (int i = 29; i >= 0; i--) {
    bool opt = 0;
    if ((x & (1 << i))) opt = 1;
    if (!tree[u][opt]) tree[u][opt] = ++tot;
    u = tree[u][opt];
    siz[u]++;
  }
}
void dfs(int u, int dep, int tot) {
  if (!dep) {
    ans = min(ans, tot);
    return;
  }
  for (int i = 0; i <= 1; i++) {
    int v = tree[u][i];
    if (v) dfs(v, dep - 1, tot + max(0, siz[tree[u][i ^ 1]] - 1));
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    insert(x);
  }
  ans = 1000000000;
  dfs(0, 30, 0);
  cout << ans;
}
