#include <bits/stdc++.h>
using i32 = int;
using i64 = long long;
bool test(i32 x, i32 y) { return x >> y & 1; }
i32 main() {
  std::ios::sync_with_stdio(false);
  std::cout.tie(nullptr);
  std::cin.tie(nullptr);
  i32 n;
  std::cin >> n;
  std::vector<i32> a(n);
  for (i32 i = 0; i < n; i++) std::cin >> a[i];
  std::function<i32(i32, i32, i32)> dfs = [&](i32 d, i32 l, i32 r) {
    if (d == -1 || r <= l + 1) return 0;
    std::vector<i32> t[2];
    for (i32 i = l; i < r; i++) t[test(a[i], d)].push_back(a[i]);
    i32 j = std::copy(t[0].begin(), t[0].end(), a.begin() + l) - a.begin();
    std::copy(t[1].begin(), t[1].end(), a.begin() + j);
    i32 size0 = j - l, size1 = r - j;
    i32 cost0 = dfs(d - 1, l, j), cost1 = dfs(d - 1, j, r);
    return std::min(cost0 + std::max(0, size1 - 1),
                    cost1 + std::max(0, size0 - 1));
  };
  std::cout << dfs(30, 0, n) << "\n";
  return 0;
}
