#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
template <typename T>
void ckmin(T& a, const T& b) {
  a = min(a, b);
}
template <typename T>
void ckmax(T& a, const T& b) {
  a = max(a, b);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace __input {
template <typename T1, typename T2>
istream& operator>>(istream& i, pair<T1, T2>& p) {
  i >> p.first >> p.second;
  return i;
}
template <typename T, size_t N>
istream& operator>>(istream& i, array<T, N>& v) {
  for (auto& e : v) {
    i >> e;
  }
  return i;
}
template <typename T>
istream& operator>>(istream& i, vector<T>& v) {
  for (auto& e : v) {
    i >> e;
  }
  return i;
}
}  // namespace __input
using namespace __input;
namespace __output {
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& t) {
  return o << "(" << t.first << ", " << t.second << ")";
}
template <typename T, size_t N>
ostream& operator<<(ostream& o, const array<T, N>& a) {
  o << "[";
  for (int i = 0; i < N; i++) {
    if (i) o << ", ";
    o << a[i];
  }
  return o << "]";
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (int i = 0; i < int((v).size()); i++) {
    if (i) o << ", ";
    o << v[i];
  }
  return o << "]";
}
}  // namespace __output
using namespace __output;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  const int BITS = 62;
  int N;
  cin >> N;
  vll vals(N);
  cin >> vals;
  vll uniq;
  for (int i = 0; i < (BITS); i++) {
    const ll MASK = (1ll << i) - 1;
    for (auto& v : vals) uniq.push_back(v & MASK);
  }
  sort((uniq).begin(), (uniq).end());
  uniq.erase(unique((uniq).begin(), (uniq).end()), uniq.end());
  const ll INF = LLONG_MAX / 2;
  vll dp(int((uniq).size()), INF), succ(int((uniq).size()), INF);
  dp[0] = 0;
  vll sorted = vals;
  for (int i = 0; i < (BITS); i++) {
    const ll MASK = (1ll << i) - 1;
    fill((succ).begin(), (succ).end(), INF);
    int zero = 0, one = 0;
    for (auto& v : vals)
      if (v & (1ll << i))
        one++;
      else
        zero++;
    int j = 0, zblw = 0, oblw = 0;
    int s1 = 0, s2 = 0;
    for (int s = 0; s < (int((uniq).size())); s++) {
      while (j < N && (sorted[j] & MASK) <= uniq[s]) {
        if (sorted[j] & (1ll << i))
          oblw++;
        else
          zblw++;
        j++;
      }
      while (s1 + 1 < int((succ).size()) && uniq[s1 + 1] <= uniq[s]) s1++;
      while (s2 + 1 < int((succ).size()) &&
             uniq[s2 + 1] <= uniq[s] + (1ll << i))
        s2++;
      ckmin(succ[s1], dp[s] + oblw + zero - zblw);
      ckmin(succ[s2], dp[s] + zblw + one - oblw);
    }
    swap(dp, succ);
    vll resorted(N);
    int zi = 0, oi = zero;
    for (auto& v : sorted) resorted[((v & (1ll << i)) ? oi : zi)++] = v;
    swap(sorted, resorted);
  }
  cout << dp.back() << endl;
  return 0;
}
