#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 3;
const int MAXBIT = (int)61;
const int infint = (int)1e9 + 3;
const long long inf = (long long)1e17;
long long n, a[MAXN], dp[MAXBIT][MAXN];
long long lg;
bool cmp(long long i, long long j) {
  long long x = i & ((1LL << (lg + 1)) - 1);
  long long y = j & ((1LL << (lg + 1)) - 1);
  return x > y;
}
void find_base() {
  long long odd = 0;
  for (int i = 1; i <= n; i++) odd += (a[i] & 1);
  dp[0][0] = n - odd;
  dp[0][odd] = min(dp[0][odd], odd);
}
string ask(long long x) {
  string s;
  while (x) {
    if (x & 1)
      s += '1';
    else
      s += '0';
    x >>= 1;
  }
  while (s.size() < MAXBIT) s += '0';
  reverse(s.begin(), s.end());
  return s;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i < MAXBIT; i++)
    for (int j = 0; j <= n; j++) dp[i][j] = inf;
  find_base();
  for (int i = 0; i < MAXBIT - 1; i++) {
    lg = i;
    sort(a + 1, a + n + 1, cmp);
    long long zero = 0, one = 0, zero_carry = 0, one_carry = 0;
    for (int j = 1; j <= n; j++)
      if ((a[j] >> (i + 1)) & 1)
        one++;
      else
        zero++;
    for (int j = 0; j <= n; j++) {
      if (j) {
        if ((a[j] >> (i + 1)) & 1)
          one--, one_carry++;
        else
          zero--, zero_carry++;
      }
      dp[i + 1][n - zero] =
          min(dp[i + 1][n - zero], dp[i][j] + one + zero_carry);
      dp[i + 1][one_carry] =
          min(dp[i + 1][one_carry], dp[i][j] + zero + one_carry);
    }
  }
  cout << min(dp[MAXBIT - 1][n], dp[MAXBIT - 1][0]);
}
