#include <bits/stdc++.h>
using namespace std;
int F[21][1 << 20], val[200010], sum[200010];
int n, len, f[200010];
inline int calc(int x, int y) {
  for (int i = len; i > 0; i--)
    if ((x & ((1 << i) - 1)) == (y >> (len - i))) return i;
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    len = s.size();
    for (int j = 0; j < len; j++) val[i] = (val[i] << 1) | (s[j] - '0');
  }
  for (int i = 2; i <= n; i++) sum[i] = sum[i - 1] + calc(val[i - 1], val[i]);
  for (int i = 0; i <= len; i++) fill(F[i], F[i] + (1 << len), -1e9);
  int ans = 0;
  for (int i = 1; i < n; i++) {
    f[i] = sum[i];
    for (int j = 0; j <= len; j++)
      f[i] = max(f[i], sum[i] + F[j][val[i + 1] >> (len - j)] + j);
    F[0][0] = max(F[0][0], f[i] - sum[i + 1]);
    for (int j = 1; j <= len; j++)
      F[j][val[i] & ((1 << j) - 1)] =
          max(F[j][val[i] & ((1 << j) - 1)], f[i] - sum[i + 1]);
    ans = max(ans, f[i] + sum[n] - sum[i + 1]);
  }
  ans = max(ans, sum[n]);
  printf("%d\n", n * len - ans);
  return 0;
}
