#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T abs(T x) {
  return x < 0 ? -x : x;
}
template <class T>
vector<T> ReadVector(int n) {
  vector<T> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  return a;
}
template <class T>
void WriteVector(const vector<T>& a) {
  for (int i = 0; i < ((int)(a).size()); ++i) {
    cout << a[i] << (i + 1 < ((int)(a).size()) ? ' ' : '\n');
  }
}
int Get(const vector<int>& a, int bit, int left, int right) {
  if (right - left <= 2) {
    return 0;
  }
  int x = a[left] ^ a[right - 1];
  while ((x & (1 << bit)) == 0) {
    --bit;
  }
  int mid = left + 1;
  while (((a[left] ^ a[mid]) & (1 << bit)) == 0) {
    ++mid;
  }
  int res = Get(a, bit - 1, left, mid) + (right - mid - 1);
  res = min(res, Get(a, bit - 1, mid, right) + (mid - left - 1));
  return res;
}
void Solve() {
  int n;
  cin >> n;
  auto a = ReadVector<int>(n);
  sort(a.begin(), a.end());
  cout << Get(a, 30, 0, n) << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  std::cin.tie(nullptr);
  int tc = 1;
  for (int ti = 0; ti < tc; ++ti) {
    Solve();
  }
  return 0;
}
