#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
const int N = 100005;
int n;
int f1(int bit, vector<int> vv) {
  if (bit == -1) return 0;
  if ((int)vv.size() <= 2) return 0;
  vector<int> on, off;
  for (int i = 0; i < (int)vv.size(); i++) {
    if ((1 << bit) & vv[i])
      on.push_back(vv[i]);
    else
      off.push_back(vv[i]);
  }
  if ((int)on.size() <= 1) return f1(bit - 1, off);
  if ((int)off.size() <= 1) return f1(bit - 1, on);
  int x = min(f1(bit - 1, on) + (int)off.size() - 1,
              f1(bit - 1, off) + (int)on.size() - 1);
  return x;
}
void solve() {
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  cout << f1(30, v);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
