#include <bits/stdc++.h>
using namespace std;
int solve(vector<int> &nums, int significant) {
  if (significant == 0) return 0;
  vector<int> s[2];
  for (int num : nums) {
    s[(num & significant) == significant].push_back(num);
  }
  if (s[0].size() < 2) {
    return solve(s[1], significant / 2);
  }
  if (s[1].size() < 2) {
    return solve(s[0], significant / 2);
  }
  int zero = max(0, (int)s[1].size() - 1) + solve(s[0], significant / 2);
  int one = max(0, (int)s[0].size() - 1) + solve(s[1], significant / 2);
  return min(zero, one);
}
int main() {
  int n;
  cin >> n;
  vector<int> nums(n);
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }
  int significant = 1 << 30;
  cout << solve(nums, significant) << endl;
}
