#include <bits/stdc++.h>
using namespace std;
const long long maxn = 7e6 + 9;
const long long mod = 1e9 + 7;
const double eps = 0.00000001;
const long long inf = 0x3f3f3f3f;
const long long INF = ~0ULL >> 1;
const double Pi = acos(-1.0);
const long long N = 2e7 + 9;
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void local() {}
long long n, m;
long long trie[maxn][3], cnt, num[maxn], ans;
void insert(long long x) {
  long long root = 0;
  for (long long i = 30; i >= 0; i--) {
    long long p = ((x >> i) & 1);
    if (!trie[root][p]) {
      trie[root][p] = ++cnt;
    }
    num[root]++;
    root = trie[root][p];
  }
}
void dfs(long long x, long long dep, long long sum) {
  if (dep == 30) {
    ans = min(ans, sum);
    return;
  }
  long long l, r;
  l = trie[x][0];
  r = trie[x][1];
  if (!r && !l) {
    return;
  } else if (!l) {
    dfs(r, dep + 1, sum);
  } else if (!r) {
    dfs(l, dep + 1, sum);
  } else {
    dfs(l, dep + 1, sum + num[r] - 1);
    dfs(r, dep + 1, sum + num[l] - 1);
  }
}
void run() {
  n = read();
  ans = inf;
  for (long long i = 1; i <= n; i++) {
    long long x = read();
    insert(x);
  }
  dfs(0, 0, 0);
  cout << ans << endl;
}
signed main() {
  local();
  long long _T = 1;
  while (_T--) {
    run();
  }
}
