#include <bits/stdc++.h>
template <typename T>
inline void rd(T& x) {
  int si = 1;
  char c = getchar();
  x = 0;
  while (!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
  while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
  x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) {
  rd(x);
  rd(args...);
}
const int kN = 4e5 + 5, kInf = 0x3f3f3f3f;
const long long kMod = 998244353, kInfLL = 0x3f3f3f3f3f3f3f3fLL;
int n, A[kN], d[kN], f[kN], g[kN], st[kN], top = 0;
int main() {
  int T = 1;
  while (T--) {
    rd(n);
    for (int i = 1; i <= n; ++i) rd(A[i]);
    std::sort(A + 1, A + n + 1);
    for (int i = 1; i <= n; ++i) d[i] = A[i] ^ A[i - 1];
    int cnt = 0;
    for (int i = 2; i <= n; ++i) {
      st[++top] = d[i];
      while (top > 1 && st[top] > st[top - 1]) {
        st[top - 1] ^= st[top];
        --top;
        ++cnt;
      }
      f[i] = cnt;
    }
    for (int i = 1; i <= n; ++i) d[i] = A[i + 1] ^ A[i];
    cnt = 0;
    top = 0;
    for (int i = n - 1; i; --i) {
      st[++top] = d[i];
      while (top > 1 && st[top] > st[top - 1]) {
        st[top - 1] ^= st[top];
        --top;
        ++cnt;
      }
      g[i] = cnt;
    }
    int ans = kInf;
    for (int i = 1; i <= n; ++i) {
      ans = std::min(f[i] + g[i], ans);
    }
    printf("%d\n", ans);
  }
  return 0;
}
