#include <bits/stdc++.h>
using namespace std;
char st[200005][25];
int g[25][1048580];
int a[200005];
int s[200005];
int c[200005];
int f[200005];
int n, m;
int check(int x, int y) {
  int ne, na, j, k = m;
  for (ne = x & 1, na = (y >> (m - 1)) & 1, x >>= 1, j = 1; j <= m;
       ne = ne | ((x & 1) << j), na = (na << 1) + ((y >> (m - j - 1)) & 1), j++,
      x >>= 1)
    if (ne == na) k = min(k, m - j);
  return k;
}
void pre() {
  int i, j, ne;
  m = strlen(st[1] + 1);
  for (i = 1; i <= n; ++i) {
    ne = 0;
    for (j = 1; j <= m; j++) ne = (ne << 1) + (st[i][j] - '0');
    c[i] = ne;
  }
  c[0] = 0;
  for (i = 1; i <= n; ++i) a[i] = check(c[i - 1], c[i]);
  a[1] = m;
  for (i = 1; i <= n; ++i) s[i] = s[i - 1] + a[i];
  memset(g, 127, sizeof(g));
}
int dp() {
  int i, j, ne, cos, little, sum, ans = 0;
  little = m;
  for (i = 1; i <= n - 1; ++i) {
    sum = little;
    for (ne = c[i + 1], j = m; j; j--, ne >>= 1) {
      cos = g[j][ne] + (m - j);
      if (cos < sum) sum = cos;
    }
    f[i] = sum + s[i];
    for (cos = c[i] >> 1, ne = c[i] & 1, j = 1; j <= m;
         j++, ne = ne | ((cos & 1) << (j - 1)), cos >>= 1)
      if (f[i] - s[i + 1] < g[j][ne]) g[j][ne] = f[i] - s[i + 1];
    if (f[i] - s[i + 1] + m < little) little = f[i] - s[i + 1] + m;
  }
  ans = s[n];
  for (i = 1; i <= n - 1; ++i) ans = min(ans, f[i] + s[n] - s[i + 1]);
  return ans;
}
int main() {
  int i;
  scanf("%d\n", &n);
  for (i = 1; i <= n; ++i) scanf("%s\n", st[i] + 1);
  pre();
  printf("%d\n", dp());
  return 0;
}
