#include <bits/stdc++.h>
using namespace std;
const unsigned mod = 998244353;
const unsigned _mod = 1e9 + 7;
const long long infi = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long qpow(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1ll) ret = ret * x;
    y >>= 1ll;
    x = x * x;
  }
  return ret;
}
long long ksm(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1ll) ret = ret * x % mod;
    y >>= 1ll;
    x = x * x % mod;
  }
  return ret;
}
long long _gcd(long long x, long long y) { return y ? _gcd(y, x % y) : x; }
long long n, dp[65][100010], a[100010], ans, mx, F[100010], G[100010], sz[2];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) a[i] = read(), mx = max(mx, a[i]);
  for (int i = 1; i <= n; ++i) a[i] = mx - a[i], F[i] = i;
  memset(dp, 0x3f, sizeof dp);
  dp[0][0] = 0;
  for (int i = 0; i <= 60; ++i) {
    sz[0] = sz[1];
    for (int j = 1; j <= n; ++j) sz[a[j] >> i & 1]++;
    int u = sz[1], v = 0;
    for (int j = 0; j <= n; ++j) {
      dp[i + 1][v] = min(dp[i + 1][v], dp[i][j] + u);
      dp[i + 1][u + v] = min(dp[i + 1][u + v], dp[i][j] + n - u);
      if (a[F[j + 1]] >> i & 1)
        v++, u--;
      else
        u++;
    }
    sz[0] += sz[1];
    for (int j = n; j >= 1; --j) G[sz[a[F[j]] >> i & 1]--] = F[j];
    swap(F, G);
    ans = dp[i + 1][0];
  }
  cout << ans << '\n';
  return 0;
}
