#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
constexpr int INF = 1000000000;
constexpr long long llINF = 1000000000000000000;
constexpr int mod = 1000000007;
constexpr double eps = 1e-8;
const double pi = acos(-1);
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int Random(int mi, int ma) {
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<int> engine(mi, ma);
  return engine(mt);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool prime(int a) {
  if (a == 1) return false;
  for (int i = 2; i * i <= a; i++) {
    if (a % i == 0) return false;
  }
  return true;
}
long long modpow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2) return modpow(a, b - 1) * a % mod;
  long long memo = modpow(a, b / 2);
  return memo * memo % mod;
}
vector<long long> kaijo, invkaijo;
void init_fact(int n) {
  kaijo.resize(n + 1);
  invkaijo.resize(n + 1);
  kaijo[0] = 1;
  for (long long i = 1; i <= n; i++) {
    kaijo[i] = kaijo[i - 1] * i;
    kaijo[i] %= mod;
  }
  for (int i = 0; i < n + 1; i++) invkaijo[i] = modpow(kaijo[i], mod - 2);
}
long long comb(int a, int b) {
  if (a < b) return 0;
  if (a < 0) return 0;
  return kaijo[a] * invkaijo[a - b] % mod * invkaijo[b] % mod;
}
long long inv(long long x) {
  x = modpow(x, mod - 2);
  return x;
}
int n, a[200010], msb[200010];
int solve(int l, int r) {
  if (r - l == 1) return 1;
  for (int i = r - 2; i >= l; i--) {
    if (msb[i] != msb[i + 1]) {
      int len = i + 1 - l, ren = r - (i + 1);
      if (len >= 2 && ren >= 2) {
        int res1 = solve(l, i + 1) + 1, res2 = solve(i + 1, r) + 1;
        return max(res1, res2);
      }
      if (len >= 2) {
        return solve(l, i + 1) + 1;
      }
      if (ren >= 2) {
        return solve(i + 1, r) + 1;
      }
      return 2;
    }
  }
  int m = msb[l] - 1;
  for (int i = l; i < r; i++) {
    a[i] -= (1 << m);
    if (a[i] == 0)
      msb[i] = 0;
    else {
      for (int j = 29; j >= 0; j--) {
        if ((a[i] >> j) & 1) {
          msb[i] = j + 1;
          break;
        }
      }
    }
  }
  return solve(l, r);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (a[i] == 0)
      msb[i] = 0;
    else {
      for (int j = 29; j >= 0; j--) {
        if ((a[i] >> j) & 1) {
          msb[i] = j + 1;
          break;
        }
      }
    }
  }
  cout << n - solve(0, n) << endl;
  return 0;
}
