#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
inline void ckmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void ckmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
using VI = vector<int>;
long long countbit(long long n) {
  return (n == 0 ? 0 : countbit(n & (n - 1)) + 1);
}
long long brute_force(vector<long long> a) {
  int n = ((int)a.size());
  sort(a.begin(), a.end());
  long long r = n * 100;
  for (long long m = a[n - 1]; m <= a[n - 1] * 4; m++) {
    long long s = 0;
    for (long long p : a) s += countbit(m - p);
    ckmin(r, s);
  }
  return r;
}
int eval(const vector<long long> &a, long long now, long long w) {
  int cost = 0;
  if (now >= w) {
    cost += upper_bound(a.begin(), a.end(), now - w) - a.begin();
  }
  {
    auto it = upper_bound(a.begin(), a.end(), now);
    auto it2 = upper_bound(a.begin(), a.end(), now + w);
    cost += it2 - it;
  }
  return cost;
}
long long solve(vector<long long> a) {
  VI f;
  vector<long long> d;
  f.push_back(0);
  d.push_back(0);
  d.push_back(1);
  long long mask = 1;
  int n = ((int)a.size());
  for (int bits = 0; bits < (62); ++bits) {
    long long w = (((long long)(1)) << (bits));
    mask |= w;
    vector<long long> new_d;
    new_d.reserve(n + 2);
    new_d.push_back(0);
    new_d.push_back(mask + 1);
    for (int i = 0; i < (n); ++i) new_d.push_back(a[i] & mask);
    sort(new_d.begin(), new_d.end());
    new_d.resize(unique(new_d.begin(), new_d.end()) - new_d.begin());
    int m = ((int)new_d.size()) - 1;
    VI new_f(m, 1000000000);
    vector<long long> sorted_masks(n);
    for (int i = 0; i < (n); ++i) sorted_masks[i] = (a[i] & mask);
    sort(sorted_masks.begin(), sorted_masks.end());
    for (int i = 0; i < (((int)f.size())); ++i)
      for (int b = 0; b < (2); ++b) {
        long long now = d[i];
        if (b) now += (((long long)(1)) << (bits));
        int cost = f[i];
        cost += eval(sorted_masks, now, w);
        ckmin(new_f[upper_bound(new_d.begin(), new_d.end(), now) -
                    new_d.begin() - 1],
              cost);
      }
    f = std::move(new_f);
    d = std::move(new_d);
  }
  return f.back();
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  while (cin >> n) {
    vector<long long> a(n);
    for (int i = 0; i < (n); ++i) cin >> a[i];
    cout << solve(a) << endl;
    break;
  }
  return 0;
}
