#include <bits/stdc++.h>
using namespace std;
const int LOG = 58;
const int maxn = 100005;
const int inf = 1000000000;
long long int a[maxn];
int dp[2][maxn];
int csum[maxn];
vector<long long int> f, s;
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;
    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 & 1][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 & 1][to] = min(dp[pos & 1][to], dp[b & 1][i] + cost);
      }
    }
    f.clear();
    s.clear();
    for (int i = 1; i <= n; i++) {
      if ((a[i] >> b) & 1)
        f.push_back(a[i]);
      else
        s.push_back(a[i]);
    }
    int idx = 0;
    for (long long int x : f) a[++idx] = x;
    for (long long int x : s) a[++idx] = x;
  }
  printf("%d", dp[LOG & 1][0]);
}
