#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
int solve(vector<int> &x, int s, int t, int b) {
  if (t - s <= 2) return 0;
  int base = 1 << b;
  int sep = t;
  for (int i = s; i < t; i++) {
    if (!(x[i] & base)) {
      sep = i;
      break;
    }
  }
  int score1 = solve(x, s, sep, b - 1);
  int score2 = solve(x, sep, t, b - 1);
  int vertex1 = (sep - s) - score1;
  int vertex2 = (t - sep) - score2;
  int score3 = max(0, min(vertex1, vertex2) - 1);
  return score1 + score2 + score3;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a) cin >> x;
  sort(a.rbegin(), a.rend());
  int ans = solve(a, 0, n, 30);
  cout << ans << endl;
  return 0;
}
