#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline ostream &operator<<(ostream &out, const pair<T, T2> &x) {
  out << x.first << " " << x.second;
  return out;
}
template <class T, class T2>
inline istream &operator>>(istream &in, pair<T, T2> &x) {
  in >> x.first >> x.second;
  return in;
}
template <class T, class T2>
inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2>
inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const long long mod = 1e9 + 7;
const long long MAX_N = 2e5 + 10;
long long solve(vector<long long> &a, long long bit) {
  if (a.empty() || bit == -1) {
    return 0;
  }
  vector<long long> lft = {}, rght = {};
  for (auto it : a) {
    if (it & (1ll << bit)) {
      lft.push_back(it);
    } else {
      rght.push_back(it);
    }
  }
  long long lftAns =
      solve(lft, bit - 1) + max(0ll, (long long)rght.size() - 1ll);
  long long rghtAns =
      solve(rght, bit - 1) + max(0ll, (long long)lft.size() - 1ll);
  return min(lftAns, rghtAns);
}
long long arr[MAX_N], n;
vector<long long> a;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    a.push_back(arr[i]);
  }
  cout << solve(a, 33) << "\n";
  return 0;
}
