#include <bits/stdc++.h>
const int N = 200010, M = N * 32;
int n, a[N], q[N], son[M][2], id[M], tot;
long long ans;
int dsu[N], hei[N];
int fnd(int x) { return x == dsu[x] ? dsu[x] : dsu[x] = fnd(dsu[x]); }
void mrg(int x, int y) {
  x = fnd(x), y = fnd(y);
  assert(x != y);
  hei[y] = std::max(hei[x], hei[y]) + 1;
  dsu[x] = y;
}
inline void ins(int p, int val) {
  int x = 0;
  for (int o = 29; ~o; o--) {
    int w = p >> o & 1;
    if (!son[x][w]) son[x][w] = ++tot;
    x = son[x][w];
  }
  id[x] = val;
}
inline std::pair<int, int> ask(int p) {
  int t = 0, x = 0;
  for (int o = 29; ~o; o--) {
    int w = p >> o & 1;
    if (son[x][w])
      x = son[x][w];
    else
      x = son[x][w ^ 1], t |= 1 << o;
  }
  return {t, id[x]};
}
void solve(int o, int l, int r) {
  if (o < 0 || l > r) return;
  int L = l - 1, R = r + 1;
  for (int i = l; i <= r; i++)
    if (a[i] >> o & 1)
      q[++L] = a[i];
    else
      q[--R] = a[i];
  for (int i = l; i <= r; i++) a[i] = q[i];
  solve(o - 1, l, L), solve(o - 1, R, r);
  if (l > L || R > r) return;
  for (int i = l; i <= L; i++) ins(a[i], i);
  int ret = ~0U >> 1, rl = -1, rr = -1;
  for (int i = R; i <= r; i++) {
    static int cur, idx;
    std::tie(cur, idx) = ask(a[i]);
    if (cur < ret) {
      ret = cur;
      rl = idx, rr = i;
    }
  }
  ans += ret;
  mrg(rl, rr);
  assert((a[rl] ^ a[rr]) == ret);
  for (int i = 0; i <= tot; i++) son[i][0] = son[i][1] = 0;
  tot = 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), dsu[i] = i;
  solve(29, 1, n);
  printf("%d", n - 1 - hei[fnd(1)]);
  return 0;
}
