#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const long long maxn = 1e5 + 10, maxm = 5e2 + 10, lg = 64, mod = 1e9 + 7,
                inf = 1e18;
long long n, a[maxn], dp[2][maxn];
long long aux = 0;
bool cmp(long long x, long long y) { return (x & aux) > (y & aux); }
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  memset(dp, 69, sizeof(dp));
  cin >> n;
  long long mx = 0;
  for (int i = 0; i < n; i++) cin >> a[i], mx = max(mx, a[i]);
  for (int i = 0; i < n; i++) a[i] = mx - a[i];
  int b = 0;
  dp[1][0] = 0;
  for (int i = 0; i < lg; i++, b = !b) {
    memset(dp[b], 69, sizeof(dp[b]));
    long long t[] = {0, 0};
    for (int j = 0; j < n; j++) t[a[j] >> i & 1]++;
    for (int tc = 0, ncar = 0; tc <= n; tc++) {
      if (dp[!b][tc] < inf) {
        dp[b][ncar] = min(dp[b][ncar], dp[!b][tc] + t[1]);
        dp[b][ncar + t[1]] = min(dp[b][ncar + t[1]], dp[!b][tc] + t[0]);
      }
      if (tc < n) {
        if (a[tc] >> i & 1)
          t[1]--, t[0]++, ncar++;
        else
          t[1]++, t[0]--;
      }
    }
    aux |= (1ll << i);
    sort(a, a + n, cmp);
  }
  cout << dp[b][0];
  return 0;
}
