#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
const int N = 205000;
int n, l, f[N], S[N], g[21][1048577], mx, nxt[43];
int v[N][23];
char s[N][23], t[43];
inline int getlcp_(int k) {
  int len = 0;
  for (register int i = 1; i <= l; i++) t[++len] = s[k][i];
  t[++len] = '#';
  for (register int i = 1; i <= l; i++) t[++len] = s[k - 1][i];
  for (int i = 2, j = 0; i <= len; i++) {
    while (j && t[j + 1] != t[i]) j = nxt[j];
    if (t[j + 1] == t[i]) j++;
    nxt[i] = j;
  }
  return nxt[len];
}
inline void umax(int &a, int b) { a = a > b ? a : b; }
int main() {
  read(n);
  for (register int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  l = strlen(s[1] + 1);
  for (register int i = 1; i <= n; i++)
    for (register int j = 1; j <= l; j++)
      s[i][j] = s[i][j] == '1', v[i][j] = (v[i][j - 1] << 1) | s[i][j];
  for (register int i = 2; i <= n; i++) S[i] = S[i - 1] + getlcp_(i);
  memset(g, 0xaf, sizeof(g));
  for (register int i = 1; i <= n; i++) {
    f[i] = S[i] + mx;
    if (i == n) break;
    for (register int j = 1; j <= l; j++)
      f[i] =
          max(f[i], j + S[i] +
                        g[j][(v[i + 1][j] - (v[i + 1][1 - 1] << (j - 1 + 1)))]);
    for (register int j = 1; j <= l; j++)
      umax(g[l - j + 1][(v[i][l] - (v[i][j - 1] << (l - j + 1)))],
           f[i] - S[i + 1]);
    mx = max(mx, f[i] - S[i + 1]);
  }
  cout << n * l - f[n];
  return 0;
}
