#include <bits/stdc++.h>
namespace pb_ds {
namespace io {
const long long MaxBuff = 1 << 15;
const long long Output = 1 << 23;
char B[MaxBuff], *S = B, *T = B;
char Out[Output], *iter = Out;
inline void flush() {
  fwrite(Out, 1, iter - Out, stdout);
  iter = Out;
}
}  // namespace io
template <class Type>
inline Type Read() {
  using namespace io;
  register char ch;
  register Type ans = 0;
  register bool neg = 0;
  while (ch = ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T)
                   ? 0
                   : *S++),
         (ch < '0' || ch > '9') && ch != '-')
    ;
  ch == '-' ? neg = 1 : ans = ch - '0';
  while (ch = ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T)
                   ? 0
                   : *S++),
         '0' <= ch && ch <= '9')
    ans = ans * 10 + ch - '0';
  return neg ? -ans : ans;
}
template <class Type>
inline void Print(register Type x, register char ch = '\n') {
  using namespace io;
  if (!x)
    *iter++ = '0';
  else {
    if (x < 0) *iter++ = '-', x = -x;
    static long long s[100];
    register long long t = 0;
    while (x) s[++t] = x % 10, x /= 10;
    while (t) *iter++ = '0' + s[t--];
  }
  *iter++ = ch;
}
}  // namespace pb_ds
using namespace pb_ds;
using namespace std;
const long long N = 1e5 + 5;
const long long inf = (long long)9187201950435737471;
long long n, mx, tot;
long long a[N], dp[75][N], tmp[N];
long long cnt[N][4], p[N], s[N];
inline void work(long long x) {
  tot = 0;
  for (long long i = 1; i <= n; ++i) s[i] = ((a[i] & (1ll << x)) != 0);
  if (!x) return;
  for (long long i = 1; i <= n; ++i)
    if (a[p[i]] & (1ll << (x - 1))) tmp[++tot] = p[i];
  for (long long i = 1; i <= n; ++i)
    if (!(a[p[i]] & (1ll << (x - 1)))) tmp[++tot] = p[i];
  for (long long i = 1; i <= n; ++i) p[i] = tmp[i];
}
signed main() {
  n = Read<long long>();
  for (long long i = 1; i <= n; ++i) mx = max(mx, a[i] = Read<long long>());
  for (long long i = 1; i <= n; ++i) a[i] = mx - a[i], p[i] = i;
  memset(dp, 127, sizeof(dp)), dp[0][0] = 0;
  memset(cnt, 0, sizeof(cnt));
  for (long long i = 0; i <= 62; ++i) {
    work(i);
    for (long long j = 1; j <= n; ++j)
      cnt[j][0] = cnt[j - 1][0] + s[p[j]],
      cnt[j][2] = cnt[j - 1][2] + (!s[p[j]]);
    for (long long j = n; j; --j)
      cnt[j][1] = cnt[j + 1][1] + s[p[j]],
      cnt[j][3] = cnt[j + 1][3] + (!s[p[j]]);
    for (long long j = 0; j <= n; ++j) {
      if (dp[i][j] == inf) continue;
      dp[i + 1][cnt[j][0]] =
          min(dp[i + 1][cnt[j][0]], dp[i][j] + cnt[j][2] + cnt[j + 1][1]);
      dp[i + 1][j + cnt[j + 1][1]] = min(dp[i + 1][j + cnt[j + 1][1]],
                                         dp[i][j] + cnt[j][0] + cnt[j + 1][3]);
    }
  }
  printf("%lld\n", dp[63][0]);
  return 0;
}
