#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 9;
const int INF = (int)1e9 + 7;
int mod = (int)1e9 + 7;
int n;
struct Node {
  int sz = 0, left = -1, right = -1;
};
vector<Node> nodes;
void add(int x) {
  int v = 0;
  for (int i = 30; i >= 0; i--) {
    nodes[v].sz++;
    if (nodes[v].right == -1) {
      Node tmp1, tmp2;
      int idx = nodes.size();
      nodes.push_back(tmp1);
      nodes[v].left = idx;
      nodes.push_back(tmp2);
      nodes[v].right = idx + 1;
    }
    if (x & (1 << i))
      v = nodes[v].right;
    else
      v = nodes[v].left;
  }
  nodes[v].sz++;
}
int ans = 0;
void DFS(int v, int sum = 0) {
  if (nodes[v].sz == 0) return;
  if (nodes[v].sz <= 2) {
    ans = max(sum + nodes[v].sz, ans);
    return;
  }
  int lsz = nodes[nodes[v].left].sz;
  int rsz = nodes[nodes[v].right].sz;
  DFS(nodes[v].left, sum + min(rsz, 1));
  DFS(nodes[v].right, sum + min(lsz, 1));
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  if (0)
    ;
  else
    cin.tie(NULL), cout.tie(NULL);
  cin >> n;
  Node tmp;
  nodes.push_back(tmp);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    add(x);
  }
  DFS(0);
  cout << n - ans << "\n";
  return 0;
}
