#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
template <class S>
inline void read(S& arg) {
  cin >> arg;
}
template <class S>
inline void readA(S Lptr, S Rptr) {
  while (Lptr != Rptr) {
    read(*Lptr);
    Lptr++;
  }
}
template <class S, class... T>
inline void read(S& arg, T&... rest) {
  read(arg);
  read(rest...);
}
char delimiter = ' ';
template <class S>
inline void write(S arg) {
  cout << arg << '\n';
}
template <class S, class... T>
inline void write(S arg, T... rest) {
  cout << arg << delimiter;
  write(rest...);
}
template <class S>
inline void writeA(S Lptr, S Rptr) {
  while (Lptr != Rptr) {
    cout << *Lptr;
    Lptr++;
    if (Lptr != Rptr) cout << delimiter;
  }
  cout << '\n';
}
template <class T, class S>
inline bool smin(T& a, S b) {
  return (T)b < a ? a = b, 1 : 0;
}
template <class T, class S>
inline bool smax(T& a, S b) {
  return a < (T)b ? a = b, 1 : 0;
}
constexpr int MOD = 1e9 + 9;
constexpr int N = 1e5 + 10;
template <typename T>
inline T mod(T& v) {
  return v = (v % MOD + MOD) % MOD;
}
template <typename T>
inline long long dom(T v) {
  return (v % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S& l, T r) {
  return mod(l += r);
}
long long po(long long v, long long u) {
  return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}
long long dp[66][N], n, a[N], b[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read(n);
  readA(a, a + n);
  long long mx = *max_element(a, a + n);
  for (int i = 0; i < (int)n; i++) a[i] = mx - a[i];
  iota(b, b + n, 0);
  vector<int> A, B;
  memset(dp, 63, sizeof(dp));
  dp[0][0] = 0;
  for (int X = 0; X < (int)62; X++) {
    for (int i = 0; i < (int)n; i++) {
      if (a[b[i]] & (1ll << X))
        A.push_back(b[i]);
      else
        B.push_back(b[i]);
    }
    int lptr = 0, rptr = 0;
    for (int i = 0; i < (int)n; i++) {
      if (a[b[i]] & (1ll << X))
        lptr++;
      else
        rptr++;
      smin(dp[X + 1][lptr], dp[X][i + 1] + rptr + (A.size() - lptr));
      smin(dp[X + 1][A.size() + rptr], dp[X][i + 1] + lptr + B.size() - rptr);
    }
    smin(dp[X + 1][0], dp[X][0] + A.size());
    smin(dp[X + 1][A.size()], dp[X][0] + B.size());
    for (int i = 0; i < (int)A.size(); i++) b[i] = A[i];
    for (int i = 0; i < (int)B.size(); i++) b[i + A.size()] = B[i];
    A.clear();
    B.clear();
  }
  cout << dp[62][0] << endl;
  return 0;
}
