#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:66777216")
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
template <class T>
inline void ra(T A[], const int& n) {
  for (int i = 0; i < (n); ++i) cin >> A[i];
}
template <class T>
inline void wa(T A[], const int& n) {
  for (int i = 0; i < (n); ++i) cout << A[i] << " ";
  cout << endl;
}
const int INF = 2e9;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 11;
const int maxp2 = 40;
int n;
int max2(int n) {
  int i = 0, x = 1;
  while (x <= n) {
    x *= 2;
    ++i;
  }
  return i - 1;
}
int solve(vector<int> V) {
  if (((int)((V).size())) <= 2) return ((int)((V).size()));
  vector<int> A[maxp2];
  int x;
  for (auto v : V) {
    x = max2(v);
    A[x + 1].push_back(v - (1 << x));
  }
  int k = 0;
  for (auto a : A)
    if (((int)((a).size())) != 0) ++k;
  int ans = 0;
  int flag = 0, pos = 0;
  for (int i = 0; i < (maxp2); ++i)
    if (((int)((A[i]).size())) != 0) {
      chkmax(ans, solve(A[i]) + flag + (k - pos - 1));
      flag = 1;
      ++pos;
    }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<int> V(n);
  for (int i = 0; i < (n); ++i) cin >> V[i];
  cout << n - solve(V) << endl;
}
