#include <bits/stdc++.h>
const int INF = 100000001;
using namespace std;
int f[21][2097153], n, m, z, x, y, a[200005], p[200005], len, ans;
int v[200005];
bool o;
char c[200005][21];
inline int check(int x, int y) {
  for (int i = 0; i <= len; ++i) {
    if ((v[x] & ((1 << (len - i)) - 1)) == v[y] >> i) return i;
  }
}
int main() {
  scanf("%d\n", &n);
  for (int i = 1; i <= n; ++i) scanf("%s\n", c[i]);
  len = a[1] = strlen(c[1]);
  for (int j = 0; j < len; ++j) v[1] = v[1] * 2 + (c[1][j] - '0');
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < len; ++j) v[i] = v[i] * 2 + (c[i][j] - '0');
    a[i] = check(i - 1, i);
  }
  for (int i = 1; i <= n; ++i) p[i] = p[i - 1] + a[i];
  memset(f, 127 / 3, sizeof(f));
  y = (1 << len) - 1;
  f[0][0] = 0;
  for (int i = 2; i <= n; ++i) {
    ans = f[0][0] + p[i - 1];
    for (int j = 1; j <= len; ++j) {
      x = v[i] >> (len - j);
      ans = min(ans, f[j][x] + p[i - 1] - j);
    }
    for (int j = 0; j <= len; ++j) {
      x = ((1 << j) - 1) & v[i - 1];
      f[j][x] = min(f[j][x], ans - (p[i] - len));
    }
  }
  ans = INF;
  for (int i = 0; i <= y; ++i)
    for (int j = 0; j <= len; ++j) ans = min(ans, f[j][i] + p[n]);
  printf("%d", ans);
}
