#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long mode(long long a) {
  while (a < 0) {
    a += mod;
  }
  return a % mod;
}
long long subt(long long a, long long b) { return mode(mode(a) - mode(b)); }
long long add(long long a, long long b) { return mode(mode(a) + mode(b)); }
long long mult(long long a, long long b) { return mode(mode(a) * mode(b)); }
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = mult(res, a);
    a = mult(a, a);
    b >>= 1;
  }
  return res;
}
const int N = 2e5 + 7;
map<int, vector<int>> graph;
map<int, bool> used;
int rec(vector<int> &v, int bit) {
  if (int((v).size()) <= 2) return 0;
  vector<int> vec[2];
  for (auto to : v) {
    int p = (to >> bit) & 1;
    vec[p].push_back(to);
  }
  int ans = 0x3f3f3f3f;
  for (int i = 0; i < 2; i++) {
    if (int((vec[i]).size()) == 0) continue;
    ans = min(ans, rec(vec[i], bit - 1) + max(int((vec[i ^ 1]).size()) - 1, 0));
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &to : v) cin >> to;
  cout << rec(v, 30);
  return 0;
}
