#include <bits/stdc++.h>
using namespace std;
long long Min(long long x, long long y) {
  if (x < y) return x;
  return y;
}
long long Max(long long x, long long y) {
  if (x > y) return x;
  return y;
}
const long long inf = 1e18;
long long read() {
  long long s = 0, h = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') h = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = s * 10 + c - '0';
    c = getchar();
  }
  return s * h;
}
void write(long long x) {
  if (x > 9) {
    short int tmp = x % 10;
    write(x / 10);
    putchar(tmp + '0');
  } else
    putchar(x + '0');
}
long long Pow(long long x, long long y, long long p) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = ans * x % p;
    x = x * x % p;
    y >>= 1;
  }
  return ans;
}
long long ls[200005 * 30], rs[200005 * 30], fa[200005 * 30], num[200005 * 30],
    root = 1, tot = 1;
long long Add(long long x) {
  long long now = root;
  num[now]++;
  for (int i = 30; i >= 0; i--) {
    if (x >= 1 << i) {
      x -= 1 << i;
      if (!rs[now]) {
        rs[now] = ++tot;
        fa[tot] = now;
      }
      now = rs[now];
    } else {
      if (!ls[now]) {
        ls[now] = ++tot;
        fa[tot] = now;
      }
      now = ls[now];
    }
    num[now]++;
  }
  return now;
}
long long Calc(long long now) {
  long long ret = 0;
  while (now != root) {
    ret += max(((now == ls[fa[now]]) ? num[rs[fa[now]]] : num[ls[fa[now]]]) - 1,
               0ll);
    now = fa[now];
  }
  return ret;
}
long long n, a[200005], p[200005], ans = inf;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) p[i] = Add(a[i] = read());
  for (int i = 1; i <= n; i++) ans = min(ans, Calc(p[i]));
  printf("%lld\n", ans);
  return 0;
}
