#include <bits/stdc++.h>
using namespace std;
long long f(vector<long long> &a, long long bit) {
  if (a.size() <= 2) return 0;
  if (bit < 0) return 0;
  vector<long long> on, off;
  for (long long x : a) {
    if (x & (1LL << bit))
      on.push_back(x);
    else
      off.push_back(x);
  }
  if (on.empty()) return f(off, bit - 1);
  if (off.empty()) return f(on, bit - 1);
  return min(on.size() - 1 + f(off, bit - 1), off.size() - 1 + f(on, bit - 1));
}
void solve_case() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long &x : a) cin >> x;
  cout << f(a, 31) << '\n';
}
signed main() {
  std::ios::sync_with_stdio(0);
  std::cout.tie(0);
  std::cin.tie(0);
  long long tt = 1;
  while (tt--) {
    solve_case();
  }
  return 0;
}
