#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
const int INF = 2000000000;
const double PI = acos(-1.0);
const int MOD = 1000000000 + 7;
const int MAXN = 5000 + 7;
int dp[MAXN][MAXN];
int highest_bit(int t) {
  int highest = 31 - __builtin_clz(t | 1);
  if (t != 0) highest++;
  return highest;
}
int solve(vector<int>& a) {
  vector<int> cnt(32, 0);
  for (auto& e : a) {
    cnt[highest_bit(e)]++;
  }
  int prev = 0;
  int best = int((a).size());
  for (int i = 0; i < int((cnt).size()); i++) {
    if (cnt[i] == 0) {
      continue;
    }
    int t_cur = 0;
    if (cnt[i] > 2) {
      vector<int> sub;
      for (auto& e : a) {
        if (highest_bit(e) == i) sub.push_back(e - (1 << (i - 1)));
      }
      t_cur = int((sub).size()) - solve(sub);
    } else {
      t_cur = cnt[i];
    }
    for (int j = i + 1; j < int((cnt).size()); j++) t_cur += min(1, cnt[j]);
    if (prev) t_cur++;
    best = min(best, int((a).size()) - t_cur);
    prev = cnt[i];
  }
  return best;
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = (0); i < (n); ++i) {
    cin >> a[i];
  }
  cout << solve(a) << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  solve();
  return 0;
}
