#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
const int N = 2e5, B = 30, NC = B * N;
int l[NC], r[NC], t[NC] = {1}, c = 1;
void insert(int x) {
  int cur = 1;
  for (auto j = (B); j-- > (0);) {
    auto& child = x >> j & 1 ? r[cur] : l[cur];
    if (child == 0) child = ++c;
    cur = child;
    ++t[cur];
  }
}
int dfs(int u) {
  return u ? min(t[l[u]] + dfs(r[u]), t[r[u]] + dfs(l[u])) - 1 : 0;
}
signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  for (auto i = (0); i < (n); ++i) {
    int x;
    cin >> x;
    insert(x);
  }
  cout << dfs(1);
}
