#include <bits/stdc++.h>
const int N = 1000005;
int a[N], n, ans, maxn, b[N], c[N];
inline void ck1(register int x) {
  register int now = 0, lst = -1;
  while (x) {
    if (!lst) {
      ++c[x], b[x] += now, lst = (x & 1), ++now, x >>= 1;
      continue;
    }
    register int tx = x, tnow = now;
    while (tx <= maxn) ++c[tx], b[tx] += tnow, ++tnow, tx <<= 1;
    lst = (x & 1), ++now, x >>= 1;
  }
}
inline void fr(int &num) {
  num = 0;
  char c = getchar();
  int p = 1;
  while (c < '0' || c > '9') c == '-' ? p = -1, c = getchar() : c = getchar();
  while (c >= '0' && c <= '9') num = num * 10 + c - '0', c = getchar();
  num *= p;
}
int main() {
  fr(n);
  for (register int i = 1; i <= n; ++i)
    fr(a[i]), maxn = (maxn > a[i] ? maxn : a[i]);
  for (register int i = 1; i <= n; ++i) ck1(a[i]);
  ans = 0x7fffffff;
  for (register int i = 1; i <= maxn; ++i)
    if (c[i] >= n) ans = (ans < b[i] ? ans : b[i]);
  printf("%d", ans);
  return 0;
}
