#include <bits/stdc++.h>
using namespace std;
void print_vec(vector<int>& a) {
  if (a.empty()) return;
  cout << a[0];
  for (int i = 1; i < a.size(); i++) cout << " " << a[i];
  cout << endl;
}
void input_vec(vector<int>& a) {
  for (auto& x : a) cin >> x;
}
void print_list(list<int>& a) {
  for (auto& x : a) cout << x << " ";
  cout << endl;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<int> divisors(int n) {
  vector<int> divs;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (i * i == n)
        divs.push_back(i);
      else {
        divs.push_back(i);
        divs.push_back(n / i);
      }
    }
  }
  return divs;
}
int f(vector<int> a, int sbit) {
  if (sbit == -1 || a.size() == 0) return 0;
  vector<int> a1, a2;
  for (auto x : a) {
    if (x & (1 << sbit))
      a1.push_back(x);
    else
      a2.push_back(x);
  }
  return min(max(0, (int)a1.size() - 1) + f(a2, sbit - 1),
             max(0, (int)a2.size() - 1) + f(a1, sbit - 1));
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  input_vec(a);
  cout << f(a, 31) << endl;
}
int main() {
  int t;
  t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
