#include <bits/stdc++.h>
using namespace std;
struct th {
  long long num;
  int id;
  bool operator<(const th &u) const {
    if (num != u.num) return num < u.num;
    return id < u.id;
  }
} p[60][100005];
int id[60][100005];
long long a[100005];
int dp[60][100005];
int fr[60][100005];
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    for (int j = 0; j < 60; j++) {
      long long ns = (1ll << j);
      if (a[i] & ns) ans--;
      p[j][i].num = (a[i] & (ns * 2 - 1));
      p[j][i].id = i;
    }
  }
  for (int j = 0; j < 60; j++) {
    sort(p[j] + 1, p[j] + n + 1);
    for (int i = 1; i <= n; i++) id[j][p[j][i].id] = i;
  }
  for (int j = 0; j < 60; j++) {
    for (int i = 0; i <= n; i++) {
      dp[j][i] = 60 * 100005 * 10;
      long long ns = p[j][i].num & (1ll << j);
      if (ns) ns = 1;
      int nx = 0;
      if (j) nx = id[j - 1][p[j][i].id];
      for (int s = 0; s < 2; s++) {
        if (s < ns) continue;
        int pls = 0;
        if (s == 1) pls = n;
        if (s > ns) {
          if (j)
            dp[j][i] = min(dp[j][i], pls + fr[j - 1][0]);
          else
            dp[j][i] = min(dp[j][i], pls);
        }
        if (s == ns) {
          if (j)
            dp[j][i] = min(dp[j][i], pls + fr[j - 1][nx]);
          else
            dp[j][i] = min(dp[j][i], pls);
        }
      }
      dp[j][i] += (n - i);
    }
    for (int i = n; i >= 0; i--)
      if (i == n)
        fr[j][i] = dp[j][i];
      else
        fr[j][i] = min(fr[j][i + 1], dp[j][i]);
  }
  ans += dp[60 - 1][n];
  cout << ans << endl;
  return 0;
}
