#include <bits/stdc++.h>
using namespace std;
ostream &operator<<(ostream &output,
                    const pair<long long int, long long int> &p) {
  output << p.first << " " << p.second;
  return output;
}
istream &operator>>(istream &input, pair<long long int, long long int> &p) {
  input >> p.first >> p.second;
  return input;
}
template <typename T>
void inline println(vector<T> args) {
  for (T i : args) cout << i << " ";
  cout << '\n';
}
long long int INF = 1e18;
long long int MOD = 998244353;
const long long int mx = 7e6;
long long int trie[mx][2], leaves[mx];
long long int ptr = 1;
long long int n;
void insert(long long int n) {
  long long int v = 0;
  for (long long int i = 30; i >= 0; i--) {
    long long int ind = __builtin_popcount(n & (1LL << i));
    if (trie[v][ind] == 0) trie[v][ind] = ptr++;
    v = trie[v][ind];
  }
  leaves[v]++;
}
long long int dfs(long long int v) {
  long long int zero = trie[v][0], one = trie[v][1];
  long long int ans = INF;
  long long int zz, oo;
  if (zero) zz = dfs(zero);
  if (one) oo = dfs(one);
  if (one) {
    leaves[v] += leaves[one];
    ans = min(ans, oo + (zero ? max(0LL, leaves[zero] - 1) : 0));
  }
  if (zero) {
    leaves[v] += leaves[zero];
    ans = min(ans, zz + (one ? max(0LL, leaves[one] - 1) : 0));
  }
  if (!one && !zero) ans = 0;
  return ans;
}
void solve() {
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    long long int temp;
    cin >> temp;
    insert(temp);
  }
  cout << dfs(0) << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
