#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
const int mod = 998244353;
const int N = 2e5 + 6;
int pk = 30;
int a[N];
struct Trie {
  static const int N = 15101000, M = 2;
  int ne[N][M], rt, L, sum[N], ans[N];
  void ini() {
    fill_n(sum, N, 0);
    L = 0, rt = newnode();
  }
  int newnode() {
    fill_n(ne[L], M, 0);
    return L++;
  }
  void add(int k, int x, int v) {
    int p = rt;
    for (int i = pk; i >= 0; i--) {
      int c = (x >> i) & 1;
      if (!ne[p][c]) ne[p][c] = newnode();
      p = ne[p][c];
    }
    sum[p] += v;
  }
  int qry(int x) {
    int p = rt;
    for (int i = pk; i >= 0; i--) {
      int c = (x >> i) & 1;
      if (ne[p][c] && sum[ne[p][c]])
        p = ne[p][c];
      else
        p = ne[p][!c];
    }
    return ans[p];
  }
  int solve() {
    int res = 0;
    for (int i = L - 1; i >= 0; i--) {
      if (sum[i] > 0) continue;
      if (!ne[i][0] || !ne[i][1])
        sum[i] = sum[ne[i][0]] + sum[ne[i][1]];
      else {
        int c0 = ne[i][0], c1 = ne[i][1];
        if (sum[c0] <= 1 || sum[c1] <= 1)
          sum[i] = sum[c0] + sum[c1];
        else {
          if (sum[c0] < sum[c1])
            res += sum[c0] - 1, sum[i] = sum[c1] + 1;
          else
            res += sum[c1] - 1, sum[i] = sum[c0] + 1;
        }
      }
    }
    return res;
  }
} T;
int s[N], f[N];
int find(int x) {
  if (f[x] == x) return x;
  return f[x] = find(f[x]);
}
int main() {
  int n, m;
  T.ini();
  scanf("%d", &n);
  for (int i = 1; i < n + 1; i++) scanf("%d", &a[i]), T.add(i, a[i], 1);
  int ans = T.solve();
  cout << ans;
  return 0;
}
