#include <bits/stdc++.h>
using namespace std;
long long input() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
const int N = 2e5 + 7;
int t[N * 40][2], siz[N * 40];
int cnt;
void insert(int &rt, long long x, int p) {
  if (!rt) rt = ++cnt;
  siz[rt]++;
  if (p == -1) return;
  int bit = (x >> p) & 1;
  insert(t[rt][bit], x, p - 1);
}
long long query(int rt) {
  long long tl = siz[t[rt][0]], tr = siz[t[rt][1]];
  if (tl > 1 && tr <= 1)
    return query(t[rt][0]);
  else if (tl <= 1 && tr > 1)
    return query(t[rt][1]);
  else if (tl > 1 && tr > 1)
    return min(tl + query(t[rt][1]) - 1, tr + query(t[rt][0]) - 1);
  else
    return 0;
}
int main() {
  int n = input();
  int root = 0;
  for (int i = 1; i <= n; i++) insert(root, input(), 30);
  printf("%lld\n", query(root));
}
