#include <bits/stdc++.h>
using namespace std;
int N, M;
char s[200000 + 5][20 + 5];
int a[(1 << 20) + 5];
const int maxn = (1 << 21) + 5;
int x[maxn], ll[maxn], rr[maxn], flag[maxn], add[maxn];
int Key;
void query(int lx, int rx, int root, int &xx, int k) {
  int zz = rx + (1 << M);
  zz >>= k;
  xx = min(xx, x[zz] + Key);
  return;
  if (root >= (1 << M) + (1 << M) || ll[root] > rx || rr[root] < lx) return;
  if (Key + x[root] >= xx) return;
  if (ll[root] >= lx && rr[root] <= rx) {
    xx = min(x[root] + Key, xx);
  }
}
void update(int xx, int root, int v) {
  if (root >= (1 << M + 1)) return;
  if (ll[root] > xx || rr[root] < xx) return;
  if (ll[root] == xx && rr[root] == xx) {
    x[root] = min(x[root], v);
    return;
  }
  update(xx, root + root, v);
  update(xx, root + root + 1, v);
  x[root] = min(x[root + root], x[root + root + 1]);
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%s", s[i]);
  M = strlen(s[0]);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      a[i] = a[i] + a[i] + s[i][M - j - 1] - '0';
    }
  }
  for (int i = 0; i < (1 << M); i++) {
    ll[i + (1 << M)] = i;
    rr[i + (1 << M)] = i;
    x[i + (1 << M)] = M * N;
  }
  for (int i = (1 << M) - 1; i > 0; i--) {
    ll[i] = ll[i + i];
    rr[i] = rr[i + i + 1];
    x[i] = min(x[i + i], x[i + i + 1]);
  }
  int L = M;
  for (int i = 1; i < N; i++) {
    int tv = x[1] + Key;
    int xx = tv + M;
    int temp = 0;
    tv = N * M;
    for (int j = 0; j < M; j++) {
      temp = (a[i] & ((1 << j + 1) - 1));
      temp = (temp << (M - j - 1));
      query(temp, temp + (1 << M - j - 1) - 1, 1, tv, M - j - 1);
      temp = (temp >> (M - j - 1));
      xx = min(tv + M - j - 1, xx);
      tv = xx;
    }
    int k = 0;
    for (; k < M; k++)
      if ((a[i - 1] >> k) == (a[i] & ((1 << M - k) - 1))) break;
    Key += k;
    xx = min(L + M, xx);
    update(a[i - 1], 1, xx - Key);
    L += k;
  }
  int xx = x[1] + Key;
  cout << xx << endl;
  return 0;
}
