#include <bits/stdc++.h>
using namespace std;
long long n, p2[50];
vector<long long> v;
long long ans(long long l, long long r) {
  if (r - l <= 2) {
    return 0;
  } else {
    long long x = 49, y = r;
    while (p2[x] > v[r]) {
      x--;
    }
    while (p2[x] <= v[y] && y >= l) {
      y--;
    }
    if (y == l - 1) {
      for (long long i = l; i <= r; i++) {
        v[i] -= p2[x];
      }
      return ans(l, r);
    } else {
      if (y == r - 1) {
        return ans(l, r - 1);
      } else if (y == l) {
        return ans(l + 1, r);
      } else {
        return min((ans(l, y) + r - y - 1), (ans(y + 1, r) + y - l));
      }
    }
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  p2[0] = 1;
  for (long long i = 1; i < 50; i++) {
    p2[i] = 2 * p2[i - 1];
  }
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long Hina;
    cin >> Hina;
    v.push_back(Hina);
  }
  sort(v.begin(), v.end());
  cout << ans(0, n - 1) << '\n';
}
