#include <bits/stdc++.h>
using namespace std;
const int INF = 987654321;
int N, L, A[200010];
int dp[21][1 << 20];
int main() {
  while (1 == scanf("%d", &N)) {
    char buf[30];
    for (int i = 0; i < (int)(N); i++) {
      scanf("%s", buf);
      A[i] = 0;
      for (L = 0; buf[L]; ++L) A[i] = A[i] << 1 | (buf[L] == '1');
    }
    for (int l = 0; l <= L; ++l)
      for (int b = 0; b < (int)(1 << l); b++) dp[l][b] = INF;
    dp[0][0] = 0;
    int base = L;
    for (int i = 1; i < N; ++i) {
      int mi = INF;
      for (int l = 0; l <= L; ++l) {
        mi = min(mi, dp[l][A[i] >> (L - l)] + base + (L - l));
      }
      int p;
      for (p = 0; p < L; ++p) {
        int msk = (1 << (L - p)) - 1;
        if ((A[i - 1] ^ (A[i] >> p)) & msk)
          continue;
        else
          break;
      }
      base += p;
      for (int l = 0; l <= L; ++l) {
        int &t = dp[l][A[i - 1] & ((1 << l) - 1)];
        t = min(t, mi - base);
      }
    }
    printf("%d\n", dp[0][0] + base);
  }
  return 0;
}
