#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, x, pa, m, c, d;
int a[200000], b[2100000];
char s[2][22];
int main() {
  scanf("%d\n", &n);
  gets(s[0]);
  m = strlen(s[0]);
  for (i = 0; i < (1 << (m + 1)); i++) b[i] = 100000000;
  for (i = 0; i < n; i++) a[i] = 100000000;
  d = m;
  for (i = 1; i < n; i++) {
    gets(s[i % 2]);
    for (c = j = m; j >= 1; j--) {
      x = 1;
      for (k = 0; k < j; k++)
        if (s[i % 2][k] != s[1 - i % 2][m - j + k]) {
          x = 0;
          break;
        }
      if (x) {
        c = m - j;
        break;
      }
    }
    for (j = 0, x = 1; j <= m; j++) {
      if (j) x = (x << 1) | (s[i % 2][j - 1] - 48);
      a[i - 1] = min(a[i - 1], b[x] + m - j - c);
    }
    a[i - 1] = min(a[i - 1], m - c);
    for (j = -1, x = 0; j < m; j++) {
      if (j >= 0) x |= (s[1 - i % 2][m - 1 - j] - 48) << j;
      b[(1 << (j + 1)) | x] = min(b[(1 << (j + 1)) | x], a[i - 1]);
    }
    d += c;
  }
  pa = d;
  for (i = 0; i < n - 1; i++)
    if (pa > a[i] + d) pa = a[i] + d;
  printf("%d\n", pa);
  return 0;
}
