#include <bits/stdc++.h>
using namespace std;
int n;
const int maxN = 100002;
const int LIM = 62;
long long a[maxN];
long long dp[LIM + 2][maxN];
const long long one = 1;
const long long INF = (one << LIM);
int zeroes[maxN], ones[maxN];
int main() {
  cin >> n;
  long long mx = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  for (int i = 1; i <= n; i++) a[i] = mx - a[i];
  memset(dp, 0x3f, sizeof(dp));
  dp[0][0] = 0;
  vector<int> f;
  for (int i = 1; i <= n; i++) f.push_back(i);
  for (int bit = 0; bit <= LIM; bit++) {
    for (int i = 1; i <= n; i++) {
      ones[i] = ones[i - 1];
      zeroes[i] = zeroes[i - 1];
      if (a[f[i - 1]] & (one << bit))
        ones[i]++;
      else
        zeroes[i]++;
    }
    for (int tail = 0; tail <= n; tail++) {
      int carry = (ones[n] - ones[n - tail]);
      dp[bit + 1][carry] =
          min(dp[bit + 1][carry],
              dp[bit][tail] + (zeroes[n] - zeroes[n - tail]) + ones[n - tail]);
      carry = n - zeroes[n - tail];
      dp[bit + 1][carry] =
          min(dp[bit + 1][carry],
              dp[bit][tail] + (ones[n] - ones[n - tail]) + zeroes[n - tail]);
    }
    vector<int> nf;
    for (int v : f)
      if (!(a[v] & (one << (bit)))) nf.push_back(v);
    for (int v : f)
      if (a[v] & (one << (bit))) nf.push_back(v);
    f = nf;
  }
  cout << dp[LIM + 1][0] << endl;
  return 0;
}
