#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
int ch[3000010][2], id[3000010], tot;
int bel[200010], n, a[200010], pos[200010], siz[3000010], f[3000010];
inline int insert(int now, int x, int p) {
  if (p == -1) return now;
  if (!ch[now][(x >> p) & 1]) ch[now][(x >> p) & 1] = ++tot;
  return insert(ch[now][(x >> p) & 1], x, p - 1);
}
inline void dp(int now) {
  siz[now] = (id[now] != 0);
  if (ch[now][0]) dp(ch[now][0]), siz[now] += siz[ch[now][0]];
  if (ch[now][1]) dp(ch[now][1]), siz[now] += siz[ch[now][1]];
  if (ch[now][0] && ch[now][1])
    f[now] = min(f[ch[now][1]] + siz[ch[now][0]] - 1,
                 f[ch[now][0]] + siz[ch[now][1]] - 1);
  else
    f[now] = f[ch[now][0] | ch[now][1]];
  return;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    bel[i] = i;
    pos[i] = insert(0, a[i], 29);
    id[pos[i]] = i;
  }
  dp(0);
  printf("%d\n", f[0]);
  return 0;
}
