#include <bits/stdc++.h>
using namespace std;
long long rec(vector<long long> v, long long bit) {
  if (v.size() <= 2) {
    return 0;
  }
  vector<long long> a, b;
  for (auto i : v) {
    if (i & (1LL << bit)) {
      a.push_back(i);
    } else {
      b.push_back(i);
    }
  }
  if (a.empty()) {
    return rec(b, bit - 1);
  } else if (b.empty()) {
    return rec(a, bit - 1);
  } else {
    return min(a.size() - 1 + rec(b, bit - 1), b.size() - 1 + rec(a, bit - 1));
  }
}
void Solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (auto& i : a) {
    cin >> i;
  }
  cout << rec(a, 30);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long testcases = 1;
  for (long long i = 1; i <= testcases; i++) {
    Solve();
  }
}
