#include <bits/stdc++.h>
using namespace std;
int n, L;
char S[200010][21];
int a[200010];
int dp[200010], *g[22], pool[(1 << 22) + 10], *p = pool;
inline int mask(int i) { return (1 << i) - 1; }
int common(int S1, int S2) {
  for (int i = L; i >= 0; i--)
    if ((S1 & mask(i)) == (S2 >> (L - i))) return i;
}
const int inf = 0x0f0f0f0f;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", S[i]);
  L = strlen(S[1]);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < L; j++) a[i] <<= 1, a[i] += S[i][j] -= '0';
  int base = 0;
  memset(pool, 0x0f, sizeof(pool));
  for (int i = 0; i <= L; i++) g[i] = p, p += 1 << i;
  dp[0] = L;
  g[0][0] = L;
  for (int i = 2; i <= n; i++) {
    int x = inf;
    for (int j = 0; j <= L; j++) x = min(x, L - j + g[j][a[i] >> (L - j)]);
    int d = L - common(a[i - 1], a[i]);
    base += d;
    dp[i - 1] = x - d;
    for (int j = 0; j <= L; j++) {
      int t = (a[i - 1] & mask(j));
      g[j][t] = min(g[j][t], x - d);
    }
  }
  int ans = inf;
  for (int i = 0; i < n; i++) ans = min(ans, base + dp[i]);
  printf("%d\n", ans);
  return 0;
}
