#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, f[25][1100001], a[200005], x, ans, mi, l[200005];
char z[25];
int gs(int x, int y) {
  int i;
  for (i = m; i > 0; i--)
    if ((a[x] & ((1 << (i)) - 1)) == (a[y] >> (m - i))) break;
  return i;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s", &z);
    m = strlen(z);
    for (j = 0; j < m; j++) a[i] = a[i] * 2 + z[j] - '0';
  }
  x = m * n;
  for (i = 2; i <= n; i++) {
    l[i] = gs(i - 1, i);
    x -= l[i];
  }
  for (i = 0; i <= m; i++)
    for (j = 0; j <= (1 << i); j++) f[i][j] = 1000000000;
  f[0][0] = 0;
  for (i = 2; i <= n; i++) {
    mi = 1000000000;
    for (j = 0; j <= m; j++) mi = min(mi, f[m - j][a[i] >> j] + j);
    for (j = 0; j <= m; j++)
      f[j][a[i - 1] & ((1 << (j)) - 1)] =
          min(f[j][a[i - 1] & ((1 << (j)) - 1)], mi - m + l[i]);
  }
  ans = 1000000000;
  for (i = 0; i <= m; i++)
    for (j = 0; j <= (1 << i); j++) ans = min(ans, f[i][j]);
  cout << x + ans << endl;
  return 0;
}
