#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const string nl = "\n";
vector<int> readVector(int n) {
  vector<int> ret(n);
  for (int i = 0; i < n; i++) cin >> ret[i];
  return ret;
}
void setIO(string name) {
  freopen((name + ".in").c_str(), "r", stdin);
  freopen((name + ".out").c_str(), "w", stdout);
}
int recur(vector<int> vec, int sig) {
  vector<int> s1, s0;
  for (int i = 0; i < vec.size(); i++) {
    if ((vec[i] & (1 << sig)) == 0) {
      s0.push_back(vec[i]);
    } else
      s1.push_back(vec[i]);
  }
  if (s1.size() < 2 && s0.size() < 2) return 0;
  if (s1.size() < 2) return recur(s0, sig - 1);
  if (s0.size() < 2) return recur(s1, sig - 1);
  return min(s0.size() - 1 + recur(s1, sig - 1),
             s1.size() - 1 + recur(s0, sig - 1));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  vector<int> a = readVector(n);
  cout << recur(a, 30) << nl;
  return 0;
}
