#include <bits/stdc++.h>
using namespace std;
int get(int x, int bt) {
  for (int i = bt; i >= 0; i--)
    if ((x & (1 << i)) > 0) return i;
  return -1;
}
int n, a[211111];
int f(int l, int r, int bt) {
  if (a[l] == a[r] || bt == -1) return r - l + 1;
  map<int, pair<int, int>> mp;
  for (int i = l; i <= r; i++) {
    int tt = get(a[i], bt);
    mp[tt].second = i;
    if (mp[tt].first == 0) mp[tt].first = i;
  }
  int ans = mp.size(), now = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    if (now == 0 || now == 1)
      ans =
          max(ans,
              (int)mp.size() +
                  f(itr->second.first, itr->second.second, itr->first - 1) - 1);
    else
      ans = max(ans,
                (int)mp.size() +
                    f(itr->second.first, itr->second.second, itr->first - 1) -
                    now);
    now++;
  }
  return ans;
}
signed main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  printf("%d\n", n - f(1, n, 30));
  return 0;
}
