#include <bits/stdc++.h>
int a, b, c, d, e, f[23][1050005], g[200005], h, i, j, k;
char w[105];
int an;
int Min(int x, int y) {
  if (x < y) return x;
  return y;
}
int main() {
  scanf("%d", &a);
  for (i = 1; i <= a; i++) {
    scanf("%s", w);
    b = strlen(w);
    for (j = 0; j < b; j++) g[i] = g[i] * 2 + w[j] - '0';
  }
  for (i = 0; i <= b; i++)
    for (j = 0; j <= 1 << b; j++) f[i][j] = (1 << 30);
  f[0][0] = 0;
  an = b;
  for (i = 2; i <= a; i++) {
    for (e = b;; e--)
      if ((g[i] >> (b - e)) == (g[i - 1] & ((1 << e) - 1))) break;
    e = b - e;
    an += e;
    d = (1 << 30);
    for (j = 0; j <= b; j++) d = Min(d, f[j][g[i] >> (b - j)] + b - j);
    for (j = 0; j <= b; j++)
      f[j][g[i - 1] & ((1 << j) - 1)] =
          Min(f[j][g[i - 1] & ((1 << j) - 1)], d - e);
  }
  e = 0;
  for (i = 0; i <= b; i++)
    for (j = 0; j <= 1 << b; j++) e = Min(e, f[i][j]);
  printf("%d\n", an + e);
  return 0;
}
