#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int last_digit(int a) {
  int res = 0;
  while (a > 1) {
    a /= 2;
    res++;
  }
  return res;
}
int calc_res(vector<int> v) {
  if (v.size() <= 1) return 0;
  int n = v.size();
  int t = last_digit(v[n - 1]);
  t = (1 << t);
  vector<int> v1;
  vector<int> v2;
  for (int i = 0; i < n; i++) {
    if ((t & v[i]) == 0) {
      v1.push_back(v[i]);
    } else {
      v2.push_back(v[i] - t);
    }
  }
  if (v1.size() == 0)
    return calc_res(v2);
  else if (v2.size() == 0)
    return calc_res(v1);
  else {
    return min(calc_res(v1) + v2.size() - 1, calc_res(v2) + v1.size() - 1);
  }
}
int main() {
  int n;
  cin >> n;
  int temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    a.push_back(temp);
  }
  sort(a.begin(), a.end());
  cout << calc_res(a) << endl;
  return 0;
}
