#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const long long MAXN = 100010;
const long long INF = 2147483600;
long long N;
long long a[MAXN + 1];
int f[63][MAXN + 1];
int p[MAXN + 1], id[MAXN + 1], nwp[MAXN + 1];
int t[2];
long long sta[2][MAXN + 1];
int cnt[2];
inline void Sort(long long x) {
  t[0] = t[1] = 0;
  for (long long i = 1; i <= N; i++) {
    long long d = (a[p[i]] >> x) & 1;
    sta[d][++t[d]] = p[i];
  }
  for (long long i = 1; i <= t[1]; i++) p[i] = sta[1][i];
  for (long long i = 1; i <= t[0]; i++) p[i + t[1]] = sta[0][i];
  return;
}
int main() {
  N = read();
  for (long long i = 1; i <= N; i++) {
    a[i] = read();
  }
  memset(f, 127, sizeof(f));
  for (long long i = 1; i <= N; i++) p[i] = i;
  Sort(0);
  f[0][0] = t[0];
  f[0][t[1]] = min(f[0][t[1]], t[1]);
  for (long long i = 1; i <= 62; i++) {
    for (long long j = 1; j <= N; j++) id[j] = p[j];
    Sort(i);
    cnt[0] = cnt[1] = 0;
    for (long long j = 1; j <= N; j++) nwp[p[j]] = j;
    int mx1 = 0, mx0 = 0;
    for (long long j = 0; j <= N; j++) {
      if (j) {
        long long x = (a[id[j]] >> i) & 1;
        ++cnt[x];
        if (x) mx1 = max(mx1, nwp[id[j]]);
        mx0 = max(mx0, nwp[id[j]]);
      }
      if (f[i - 1][j] <= i * N) {
        f[i][mx1] = min(f[i][mx1], f[i - 1][j] + cnt[1] + t[0] - cnt[0]);
        f[i][max(t[1], mx0)] =
            min(f[i][max(t[1], mx0)], f[i - 1][j] + cnt[0] + t[1] - cnt[1]);
      }
    }
  }
  printf("%d\n", f[62][0]);
  return 0;
}
