#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 29);
const int INFF = 0x7fffffff;
const long long LINF = (1ll << 60);
const long long LINFF = 0x7fffffffffffffff;
const long double PI = 3.14159265359;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long a, long long b) {
  return uniform_int_distribution<long long>(a, b)(rng);
}
int solve(vector<int> v, int most) {
  if (most == -1) return 0;
  vector<int> s0, s1;
  for (int x : v) {
    if (x & (1 << most))
      s1.push_back(x);
    else
      s0.push_back(x);
  }
  if ((int)s0.size() <= 1) return solve(s1, most - 1);
  if ((int)s1.size() <= 1) return solve(s0, most - 1);
  return min(solve(s0, most - 1) + (int)s1.size() - 1,
             solve(s1, most - 1) + (int)s0.size() - 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  cout << solve(v, 30) << '\n';
  return 0;
}
