#include <bits/stdc++.h>
using namespace std;
long long n;
long long dpf(vector<long long> v, long long x) {
  if (v.size() <= 1) return 0;
  vector<long long> hasbit;
  vector<long long> nobit;
  for (long long i = 0; i < (long long)v.size(); i++) {
    if (v[i] & (1 << x))
      hasbit.push_back(v[i]);
    else
      nobit.push_back(v[i]);
  }
  long long hassize = hasbit.size(), nosize = nobit.size();
  long long ans = 0;
  if (hassize > 1 and nosize > 1) {
    ans = min(dpf(nobit, x - 1) + hassize - 1, dpf(hasbit, x - 1) + nosize - 1);
  } else {
    ans = dpf(nobit, x - 1) + dpf(hasbit, x - 1);
  }
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<long long> v;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    v.push_back(x);
  }
  cout << dpf(v, 30);
}
