#include <bits/stdc++.h>
constexpr int maxn = 2e5 + 5;
int ch[maxn * 30][2], sz[maxn * 30], a[maxn], cnt, n;
void insert(int x) {
  int now = 0;
  for (int i = 29; i; --i) {
    if (!ch[now][(x >> i) & 1]) {
      ch[now][(x >> i) & 1] = ++cnt;
    }
    now = ch[now][(x >> i) & 1];
    sz[now]++;
  }
}
int dfs(int now) {
  int left = ch[now][0], right = ch[now][1];
  if (left && right) {
    return std::min(sz[left] - 1 + dfs(right), sz[right] - 1 + dfs(left));
  }
  if (left) {
    return dfs(left);
  }
  if (right) {
    return dfs(right);
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    insert(a[i]);
  }
  std::cout << dfs(0) << std::endl;
  return 0;
}
