#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long OO = 1LL << 61;
const long long MOD = 10007;
const int maxn = 200000 + 5;
int dp[21][1 << 20];
int a[maxn];
char str[25];
void cmin(int &a, int b) {
  if (b < a) a = b;
}
int main() {
  int n, m;
  while (scanf("%d", &n) != EOF) {
    memset(a, 0, sizeof a);
    memset(dp, 0x3f, sizeof dp);
    for (int i = 1; i <= n; i++) {
      scanf("%s", str);
      m = strlen(str);
      for (int j = 0; j < m; j++) a[i] = (a[i] << 1) | (str[j] - '0');
    }
    dp[0][0] = 0;
    int ans = m;
    for (int i = 2, j; i <= n; i++) {
      for (j = m; (a[i - 1] & ((1 << j) - 1)) != (a[i] >> m - j) && j; j--)
        ;
      ans += m - j;
      int k = oo;
      for (int p = 0; p <= m; p++) cmin(k, dp[p][a[i] >> m - p] - p + j);
      for (int p = 0; p <= m; p++) cmin(dp[p][a[i - 1] & ((1 << p) - 1)], k);
    }
    int t = 0;
    for (int i = 0; i <= m; i++)
      for (int j = 0; j < (1 << i); j++) cmin(t, dp[i][j]);
    printf("%d\n", ans + t);
  }
  return 0;
}
