#include <bits/stdc++.h>
using namespace std;
const int N = 100009;
int n, pos[N], sum[N][2], f[63][N], now;
long long m, a[N];
inline bool cmp(int x, int y) {
  return (a[x] & ((1LL << now) - 1)) < (a[y] & ((1LL << now) - 1));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) a[i] = a[n] - a[i], pos[i] = i;
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (int k = 0; k <= 60; ++k) {
    now = k, sort(pos + 1, pos + n + 1, cmp);
    for (int i = 1; i <= n; ++i) {
      sum[i][0] = sum[i - 1][0], sum[i][1] = sum[i - 1][1];
      ++sum[i][(a[pos[i]] >> k) & 1];
    }
    for (int i = 0; i <= n; ++i) {
      int unup0 = sum[n - i][0], unup1 = sum[n - i][1],
          up0 = sum[n][0] - sum[n - i][0], up1 = sum[n][1] - sum[n - i][1];
      f[k + 1][up1] = min(f[k + 1][up1], f[k][i] + up0 + unup1);
      f[k + 1][n - unup0] = min(f[k + 1][n - unup0], f[k][i] + unup0 + up1);
    }
  }
  printf("%d\n", f[61][0]);
  return 0;
}
