#include <bits/stdc++.h>
using namespace std;
const long long logn = 63;
const long long inf = 1e18;
void upd(long long& a, const long long& b) { a = min(a, b); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  long long mx = *max_element(a.begin(), a.end());
  for (int i = 0; i < n; i++) b[i] = mx - a[i];
  vector<vector<long long> > dp(logn, vector<long long>(n + 1, inf));
  dp[0][0] = 0;
  vector<int> s;
  for (int i = 0; i < n; i++) s.push_back(i);
  for (long long bit = 0; bit + 1 < logn; bit++) {
    if (bit) {
      vector<int> nws;
      for (int i : s)
        if (!(b[i] & (1ll << (bit - 1)))) nws.push_back(i);
      for (int i : s)
        if (b[i] & (1ll << (bit - 1))) nws.push_back(i);
      s = nws;
    }
    vector<long long> pf0(n + 1, 0), pf1(n + 1, 0);
    for (int i = 0; i < n; i++) {
      pf0[i + 1] = pf0[i], pf1[i + 1] = pf1[i];
      if (b[s[i]] & (1ll << bit))
        pf1[i + 1]++;
      else
        pf0[i + 1]++;
    }
    for (int sf = 0; sf <= n; sf++) {
      int b0ones = pf1[n - sf] + (pf0[n] - pf0[n - sf]);
      int b0carry = pf1[n] - pf1[n - sf];
      upd(dp[bit + 1][b0carry], dp[bit][sf] + b0ones);
      int b1ones = pf0[n - sf] + (pf1[n] - pf1[n - sf]);
      int b1carry = n - pf0[n - sf];
      upd(dp[bit + 1][b1carry], dp[bit][sf] + b1ones);
    }
  }
  cout << dp[logn - 1][0] << "\n";
  return 0;
}
