#include <bits/stdc++.h>
using namespace std;
inline int hibit(const int a) {
  for (register int i = 30; i >= 0; --i)
    if (a & (1 << i)) return i + 1;
  return 0;
}
int n;
int work(vector<vector<int> >& arr) {
  int res = 0, ans, fr = 0;
  for (int i = 0; i <= 31; ++i)
    if (!arr[i].empty()) res += arr[i].size() - 1;
  ans = res;
  for (int i = 0; i <= 31; ++i)
    if (!arr[i].empty() && i == 0)
      ++fr;
    else if (!arr[i].empty()) {
      const int len = arr[i].size();
      vector<vector<int> > _arr(35);
      for (int j = 0; j < len; ++j) {
        const int now = arr[i][j] ^ (1 << (i - 1)), hi = hibit(now);
        _arr[hi].push_back(now);
      }
      ans = min(ans, res - len + 1 + work(_arr) + max(0, fr - 1));
      ++fr;
    }
  return ans;
}
int main() {
  scanf("%d", &n);
  vector<vector<int> > arr(35);
  while (n--) {
    int i;
    scanf("%d", &i);
    arr[hibit(i)].push_back(i);
  }
  cout << work(arr);
}
