#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
const int maxn = 1000010;
const int mod = 1000000007;
const long double eps = 1e-9;
const int inf = ((1ll << 31ll) - 1ll);
const int INF = 1ll * mod * mod;
const long double pi = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int qpow(int b, int e) {
  if (!e) return 1;
  if (e & 1) return qpow(b, e - 1) * b % mod;
  int pwur = qpow(b, e >> 1);
  return pwur * pwur % mod;
}
int modinv(int x) { return qpow(x, mod - 2); }
int n, a[maxn];
set<int> second;
int first(vector<int> v, int g, vector<int> cnt) {
  if (v.empty()) return 0;
  if (g == 0) {
    return ((int)v.size() >= 1);
  }
  for (int i = 0; i <= g; i++) cnt.push_back(0);
  vector<int> tcnt;
  int diff = 0;
  for (auto i : v) {
    int lg = 32 - __builtin_clz(i);
    if (i == 0) lg = 0;
    cnt[lg]++;
    if (cnt[lg] == 1) diff++;
  }
  cnt[g] = (cnt[g] > 0);
  for (int i = g - 1; i >= 0; i--) cnt[i] = cnt[i + 1] + (cnt[i] > 0);
  int res = diff;
  vector<int> w;
  for (int i = 0; i < g; i++) {
    w.clear();
    bool bt = 0;
    for (auto j : v) {
      int lg = 32 - __builtin_clz(j);
      if (j == 0) lg = 0;
      if (lg == i) {
        if (j > 0)
          w.push_back(j - (1 << (lg - 1)));
        else
          w.push_back(j);
      }
      if (lg < i) bt = 1;
    }
    res = max(res, cnt[i + 1] + bt + first(w, i, tcnt));
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(0);
  srand(time(NULL));
  cin >> n;
  vector<int> w;
  vector<int> tcnt;
  set<int> sw;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != 0) w.push_back(a[i]);
    int lg = 32 - __builtin_clz(a[i]);
    if (a[i] == 0) lg = 0;
    sw.insert(lg);
  }
  int ans = sw.size();
  ans = max(ans, first(w, 32, tcnt));
  cout << n - ans << '\n';
  return 0;
}
