#include <bits/stdc++.h>
using namespace std;
const int LOG = 60;
const int maxn = 100005;
const int inf = 1000000000;
long long int a[maxn];
int dp[LOG + 1][maxn];
int csum[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) dp[0][i] = inf;
  for (int b = 0; b < LOG; b++) {
    int pos = b + 1;
    sort(a + 1, a + n + 1, [&](long long int x, long long int y) {
      return x % (1LL << b) > y % (1LL << b);
    });
    for (int i = 1; i <= n; i++) csum[i] = csum[i - 1] + ((a[i] >> b) & 1);
    for (int i = 0; i <= n; i++) dp[pos][i] = inf;
    for (int i = 0; i <= n; i++) {
      for (int w = 0; w <= 1; w++) {
        int l1 = csum[i], l0 = i - l1;
        int r1 = csum[n] - l1, r0 = (n - i) - r1;
        int to = l1 + (l0 + r1) * !w;
        int cost = (l1 + r0) * w + (l0 + r1) * !w;
        dp[pos][to] = min(dp[pos][to], dp[pos - 1][i] + cost);
      }
    }
  }
  printf("%d", dp[LOG][0]);
}
