#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int INF64 = mod * mod + 1;
long long int f(vector<long long int> a, long long int bit) {
  if (bit == -1) return 0;
  long long int n = a.size();
  vector<long long int> high, low;
  for (auto it : a) {
    if (it & (1 << bit))
      high.push_back(it);
    else
      low.push_back(it);
  }
  bit--;
  if (high.size() <= 1)
    return f(low, bit);
  else if (low.size() <= 1)
    return f(high, bit);
  long long int c1 = f(low, bit), c2 = f(high, bit);
  return min(low.size() + c2 - 1, high.size() + c1 - 1);
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  cout << f(a, 30);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int T = 1;
  for (long long int i = 1; i <= T; i++) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
