#include <bits/stdc++.h>
using namespace std;
int n;
string ss[200005];
int rec(int st, int dr, int ind) {
  if (st == dr) return 1;
  if (st == dr - 1) {
    return 2;
  }
  if (ss[st][ind] == ss[dr][ind]) {
    return rec(st, dr, ind + 1);
  }
  int sta, dre, aa;
  for (int i = st; i <= dr; i++) {
    if (ss[i][ind] == '1') {
      aa = i;
      sta = rec(st, i - 1, ind + 1);
      dre = rec(i, dr, ind + 1);
      break;
    }
  }
  if (aa > st + 1 and aa <= dr - 1) {
    return 1 + max(sta, dre);
  }
  if (aa == st + 1) {
    return rec(aa, dr, ind + 1) + 1;
  }
  return rec(st, dr - 1, ind + 1) + 1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    string s = "";
    cin >> a;
    while (a) {
      s += char('0' + a % 2);
      a /= 2;
    }
    for (int k = s.size() + 1; k <= 30; k++) {
      s += '0';
    }
    for (int j = 0; j < s.size() / 2; j++) {
      swap(s[j], s[s.size() - j - 1]);
    }
    ss[i] = s;
  }
  sort(ss + 1, ss + n + 1);
  cout << n - rec(1, n, 0);
  return 0;
}
