#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int N = 200005;
vector<int> a;
int solve(vector<int> &a, int k) {
  if (a.size() == 0 || k == -1) return 0;
  vector<int> b, c;
  for (auto x : a) {
    if (x >> k & 1)
      b.push_back(x);
    else
      c.push_back(x);
  }
  return min(solve(b, k - 1) + max(0, (int)c.size() - 1),
             solve(c, k - 1) + max(0, (int)b.size() - 1));
}
int main() {
  int n, x;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x, a.push_back(x);
  printf("%d\n", solve(a, 29));
  return 0;
}
