#include <bits/stdc++.h>
using namespace std;
int dnc(vector<int> &arr, int bit) {
  if (arr.size() == 1) {
    return 0;
  }
  if (arr.size() == 2) {
    return 1;
  }
  vector<int> a, b;
  int aval = 0, bval = 0;
  if (bit != 1) {
    for (int i = 0; i < arr.size(); i++) {
      if (arr[i] >= bit) {
        a.push_back(arr[i] - bit);
      } else {
        b.push_back(arr[i]);
      }
    }
    if (!a.empty()) {
      aval = dnc(a, bit / 2);
    }
    if (!b.empty()) {
      bval = dnc(b, bit / 2);
    }
  }
  if (a.empty()) {
    return bval;
  }
  if (b.empty()) {
    return aval;
  }
  return min(aval + (int)b.size() - 1, bval + (int)a.size() - 1);
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> arr;
  for (int i = 0; i < n; i++) {
    int input;
    scanf("%d", &input);
    arr.push_back(input);
  }
  printf("%d\n", dnc(arr, 1 << 29) - 1);
  return 0;
}
