#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
void debug(const vector<T>& v) {
  for (int i = 0; i < (int)v.size(); ++i) cout << v[i] << " ";
  cout << endl;
}
int solve(vector<int>& v) {
  if (v.size() == 1) return 0;
  vector<vector<int>> msb(33);
  for (int x : v) {
    if (x == 0)
      msb[0].push_back(x);
    else {
      int b = 31 - __builtin_clz(x);
      msb[b + 1].push_back(x ^ (1 << b));
    }
  }
  int ans = 1e9;
  for (int i = 0; i <= 32; ++i) {
    if (msb[i].empty()) continue;
    int cnt = 0;
    for (int j = i + 1; j <= 32; ++j) {
      if (!msb[j].empty()) cnt += msb[j].size() - 1;
    }
    bool flag = false;
    for (int j = 0; j < i; ++j) {
      if (!msb[j].empty()) flag = true, cnt += msb[j].size();
    }
    if (flag) --cnt;
    cnt += solve(msb[i]);
    ans = min(ans, cnt);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int& x : a) cin >> x;
  cout << solve(a) << endl;
}
