#include <bits/stdc++.h>
using namespace std;
const long long INF(0x3f3f3f3f3f3f3f3fll);
const long long inf(0x3f3f3f3f);
const long long N = 4e6 + 10;
long long tree[N][2], cnt[N], tot;
void insert(long long n) {
  long long root = 0;
  for (long long j = 30; j >= 0; j--) {
    long long x = n >> j & 1;
    if (!tree[root][x]) tree[root][x] = ++tot;
    cnt[root]++, root = tree[root][x];
  }
}
long long ans;
void dfs(long long u, long long sum, long long res) {
  if (sum == 30) {
    ans = min(ans, res);
    return;
  }
  if (tree[u][0]) {
    long long x = cnt[tree[u][1]];
    if (!tree[u][1]) x = 1;
    dfs(tree[u][0], sum + 1, res + x - 1);
  }
  if (tree[u][1]) {
    long long x = cnt[tree[u][0]];
    if (!tree[u][0]) x = 1;
    dfs(tree[u][1], sum + 1, res + x - 1);
  }
}
long long n, a[N];
signed main() {
  std::ios::sync_with_stdio(false);
  ans = inf;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    insert(x);
  }
  dfs(0, 0, 0);
  cout << ans << '\n';
  return 0;
}
