#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T& x) {
  static char c;
  static int f;
  for (c = getchar(), f = 1; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -f;
  for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + (c & 15);
  x *= f;
}
template <typename T>
void write(T x) {
  static char q[65];
  int cnt = 0;
  if (x < 0) putchar('-'), x = -x;
  q[++cnt] = x % 10, x /= 10;
  while (x) q[++cnt] = x % 10, x /= 10;
  while (cnt) putchar(q[cnt--] + '0');
}
const int maxn = 200005;
int a[maxn], b[maxn], c[maxn];
int solve(int pos, int l, int r) {
  if (l + 1 >= r) return 0;
  while ("Imakf ak ioi") {
    int o = (a[l] >> pos), ok = true;
    for (int i = l + 1; i <= r && ok; ++i) ok &= ((a[i] >> pos) == o);
    if (!ok) break;
    --pos;
  }
  int bcnt = 0, ccnt = 0;
  for (int i = l; i <= r; ++i) {
    if ((a[i] >> pos) & 1)
      b[++bcnt] = a[i];
    else
      c[++ccnt] = a[i];
  }
  for (int i = 1; i <= bcnt; ++i) a[l - 1 + i] = b[i];
  for (int i = 1; i <= ccnt; ++i) a[l + bcnt - 1 + i] = c[i];
  return min(solve(pos - 1, l, l + bcnt - 1) + ccnt - 1,
             solve(pos - 1, l + bcnt, r) + bcnt - 1);
}
int main() {
  int n;
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]);
  write(solve(30, 1, n)), putchar('\n');
  return 0;
}
