#include <bits/stdc++.h>
using namespace std;
const int N = 2000005, M = 21;
int n, m, A[N], dp[N], PS[N], Best[M][N];
string S[N];
inline int GetF(int b, int a) {
  for (int h = 0; h <= m; h++, a >>= 1)
    if (a == (b & ((1 << (m - h)) - 1))) return (h);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> S[i];
    m = (int)S[i].size();
    for (int h = 0; h < (int)S[i].size(); h++)
      A[i] = (A[i] << 1) | (S[i][h] == '1');
    if (i > 1)
      PS[i] = PS[i - 1] + GetF(A[i - 1], A[i]);
    else
      PS[i] = m;
  }
  int Mn = PS[n];
  memset(Best, 63, sizeof(Best));
  for (int i = 2; i <= n; i++) {
    dp[i] = PS[i - 1] + m;
    for (int h = 0; h <= m; h++)
      dp[i] = min(dp[i], Best[m - h][(A[i] >> h)] + h + PS[i - 1]);
    for (int h = 0; h <= m; h++) {
      int b = (A[i - 1] & ((1 << h) - 1));
      Best[h][b] = min(Best[h][b], dp[i] - PS[i]);
    }
    Mn = min(Mn, dp[i] + PS[n] - PS[i]);
  }
  return !printf("%d\n", Mn);
}
