#include <bits/stdc++.h>
using namespace std;
int n, m, k, ans, t, a[200100], f[22][1100000];
char s[30];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    m = strlen(s);
    for (int j = 0; j < m; j++) a[i] = a[i] * 2 + s[j] - '0';
  }
  memset(f, 0x40, sizeof(f));
  ans = m;
  f[0][0] = 0;
  for (int i = 1; i < n; i++) {
    for (k = m; k; k--)
      if ((a[i - 1] & ((1 << (k)) - 1)) == (a[i] >> (m - k))) break;
    t = 1 << 30;
    ans += m - k;
    for (int j = 0; j < m + 1; j++) t = min(t, f[m - j][a[i] >> j] + j);
    for (int j = 0; j < m + 1; j++)
      f[j][a[i - 1] & ((1 << (j)) - 1)] =
          min(f[j][a[i - 1] & ((1 << (j)) - 1)], t - m + k);
  }
  t = 1 << 30;
  for (int i = 0; i < m + 1; i++)
    for (int j = 0; j < (1 << i); j++) t = min(t, f[i][j]);
  printf("%d\n", t + ans);
}
