#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, f[2][N];
long long a[N], mx, v1[N], v2[N];
void upd(int& x, int y) { x = (x < y ? x : y); }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]), mx = max(mx, a[i]);
  for (int i = 1; i <= n; ++i) a[i] = mx - a[i];
  memset(f[1], 0x3f, sizeof(int) * (n + 1));
  f[1][0] = 0;
  for (int i = 0; i < 64; ++i) {
    memset(f[i & 1], 0x3f, sizeof(int) * (n + 1));
    int c[2] = {0}, t = 0;
    for (int j = 1; j <= n; ++j) ++c[a[j] >> i & 1];
    upd(f[i & 1][0], f[~i & 1][0] + c[1]);
    upd(f[i & 1][c[1]], f[~i & 1][0] + c[0]);
    for (int j = 1; j <= n; ++j) {
      if (a[j] >> i & 1)
        --c[1], ++c[0], ++t;
      else
        --c[0], ++c[1];
      upd(f[i & 1][t], f[~i & 1][j] + c[1]);
      upd(f[i & 1][t + c[1]], f[~i & 1][j] + c[0]);
    }
    int id1 = 0, id2 = 0, id = 0;
    for (int j = 1; j <= n; ++j)
      (a[j] >> i & 1) ? v1[++id1] = a[j] : v2[++id2] = a[j];
    for (int j = 1; j <= id1; ++j) a[++id] = v1[j];
    for (int j = 1; j <= id2; ++j) a[++id] = v2[j];
  }
  printf("%d", f[1][0]);
}
