#include <bits/stdc++.h>
using namespace std;
int n, m, a[200003], f[23][1048579];
char s[23];
int getLen(int x, int y) {
  for (int i = m;; --i)
    if (!i || (x & ((1 << i) - 1)) == (y >> (m - i))) return i;
}
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] << 1) + s[j] - '0';
  }
  memset(f, 44, sizeof(f));
  f[0][0] = 0;
  int ans = m;
  for (int i = 1; i < n; ++i) {
    int x = m - getLen(a[i - 1], a[i]), v = (~0U >> 1);
    ans += x;
    for (int j = 0; j <= m; ++j) v = min(v, f[j][a[i] >> (m - j)] + m - j);
    for (int j = 0; j <= m; ++j)
      f[j][a[i - 1] & ((1 << j) - 1)] =
          min(f[j][a[i - 1] & ((1 << j) - 1)], v - x);
  }
  int v = (~0U >> 1);
  for (int i = 0; i <= m; ++i)
    for (int j = 0; j < (1 << m); ++j) v = min(v, f[i][j]);
  printf("%d\n", ans + v);
  return 0;
}
