#include <bits/stdc++.h>
using namespace std;
char st[200005][25];
int g[25][1048580];
int bin[200005];
int a[200005];
int s[200005];
int f[200005];
int n, m;
int check(int x, int y) {
  int a, b, i, s = m;
  a = x & 1, b = (y >> (m - 1)) & 1, x >>= 1;
  for (i = 1; i <= m; ++i) {
    if (a == b) s = min(s, m - i);
    a = a | ((x & 1) << i);
    b = (b << 1) + ((y >> (m - i - 1)) & 1);
    x >>= 1;
  }
  return s;
}
void pre() {
  int i, j, k;
  m = strlen(st[1] + 1);
  for (i = 1; i <= n; ++i) {
    k = 0;
    for (j = 1; j <= m; ++j) k = (k << 1) + (st[i][j] - '0');
    bin[i] = k;
  }
  for (i = 1; i <= n; ++i) a[i] = check(bin[i - 1], bin[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, t1, t2, mins, sum, ans;
  mins = m;
  ans = 0;
  for (i = 1; i < n; ++i) {
    sum = mins;
    t1 = bin[i + 1];
    for (j = m; j > 0; --j) {
      sum = min(sum, g[j][t1] + m - j);
      t1 >>= 1;
    }
    f[i] = sum + s[i];
    t1 = bin[i] >> 1, t2 = bin[i] & 1;
    for (j = 1; j <= m; ++j) {
      g[j][t2] = min(g[j][t2], f[i] - s[i + 1]);
      t2 = t2 | ((t1 & 1) << j);
      t1 >>= 1;
    }
    mins = min(mins, f[i] - s[i + 1] + m);
  }
  ans = s[n];
  for (i = 1; i < n; ++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;
}
