#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
int n, a[200005];
int rt = 1, tot = 1, sz[200005 * 30], dp[200005 * 30], ch[200005 * 30][2];
void ins(int x) {
  int u = 1;
  for (register int i = (30); i >= (0); --i) {
    int c = (x >> i & 1);
    if (!ch[u][c]) ch[u][c] = ++tot;
    u = ch[u][c];
  }
  sz[u]++;
}
void dfs(int u) {
  if (!u) return;
  dfs(ch[u][0]), dfs(ch[u][1]), sz[u] += sz[ch[u][0]] + sz[ch[u][1]];
  if (sz[ch[u][0]] <= 1 && sz[ch[u][1]] <= 1) return;
  dp[u] = 2e9;
  for (register int x = (0); x <= (1); ++x)
    dp[u] = min(dp[u], max(0, sz[ch[u][x]] - 1) + dp[ch[u][!x]]);
}
int main() {
  n = read();
  for (register int i = (1); i <= (n); ++i) {
    a[i] = read();
    ins(a[i]);
  }
  dfs(1);
  cout << dp[1];
  return 0;
}
