#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
char buf[25];
int a[200010], f[21][1 << 21];
void checkmin(int &a, int b) {
  if (b < a) a = b;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", buf);
    m = strlen(buf);
    for (int j = 0; j < m; j++) a[i] = (a[i] << 1) | (buf[j] - '0');
  }
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  ans = m;
  for (int i = 2; i <= n; i++) {
    int j, k, l = 0x3f3f3f3f;
    for (j = m; j; j--)
      if ((a[i - 1] & ((1 << j) - 1)) == (a[i] >> (m - j))) break;
    ans += (k = m - j);
    for (j = 0; j <= m; j++) checkmin(l, f[m - j][a[i] >> j] + j);
    for (j = 0; j <= m; j++) checkmin(f[j][a[i - 1] & ((1 << j) - 1)], l - k);
  }
  int tmp = 0x3f3f3f3f;
  for (int i = 0; i <= m; i++)
    for (int j = 0; j < (1 << i); j++) checkmin(tmp, f[i][j]);
  printf("%d\n", ans + tmp);
  return 0;
}
