#include <bits/stdc++.h>
using namespace std;
const int sz = 5e5;
int n;
long long a[sz];
inline int calcMSB(int num, int upper) {
  for (int i = upper - 2; i >= 0; i--) {
    if ((num >> i) & 1) return i + 1;
  }
  return 0;
}
int foo(int i, int j, int msb) {
  if (j - i <= 1) return 0;
  vector<pair<pair<int, int>, int>> v;
  vector<int> costs, szs;
  int prv = calcMSB(a[i], msb), prvStart = i;
  for (int l = i + 1; l <= j; l++) {
    int xx = calcMSB(a[l], msb);
    if (xx != prv) {
      v.push_back({{prvStart, l - 1}, prv});
      szs.push_back(l - prvStart);
      prv = xx;
      prvStart = l;
    }
  }
  v.push_back({{prvStart, j}, prv});
  szs.push_back(j - prvStart + 1);
  int vsz = v.size();
  for (int i = 0; i < vsz; i++)
    costs.push_back(foo(v[i].first.first, v[i].first.second, v[i].second));
  long long bst = n;
  for (int i = 0; i < vsz; i++) {
    long long bef = 0, aft = 0;
    for (int j = 0; j < i; j++) bef += szs[j];
    for (int j = i + 1; j < vsz; j++) aft += (szs[j] - 1);
    bst = min(bst, (i ? bef - 1 : 0) + aft + costs[i]);
  }
  return bst;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  long long tmp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  cout << min(n - 2, foo(0, n - 1, 31)) << '\n';
  return 0;
}
