#include <bits/stdc++.h>
using namespace std;
int Pow(int a, int b, int md, int ans = 1) {
  for (; b; b >>= 1, a = a * a % md)
    if (b & 1) ans = ans * a % md;
  return ans % md;
}
const int MAXN = 2e5 + 10;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int LOG = 21;
int dp[MAXN], ps[MAXN], mask[MAXN][LOG], rmask[MAXN][LOG],
    mn[LOG][(1LL << LOG) + 10], n, m;
string s[MAXN];
int cost(int x, int y) {
  for (int i = m; i; i--) {
    if (mask[y][i] == rmask[x][i]) return m - i;
  }
  return m;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    m = (int)s[i].size();
    s[i] = '0' + s[i];
    for (int j = 1; j <= m; j++) {
      mask[i][j] = mask[i][j - 1] * 2 + (s[i][j] - '0');
    }
    for (int j = m; j; j--) {
      rmask[i][m - j + 1] =
          rmask[i][m - j] + (s[i][j] - '0') * (1LL << (m - j));
    }
  }
  ps[1] = dp[1] = m;
  for (int i = 2; i <= n; i++) {
    ps[i] = ps[i - 1] + cost(i - 1, i);
    dp[i] = ps[i - 1] + m;
  }
  for (int i = 0; i < LOG; i++) fill(mn[i], mn[i] + (1LL << LOG) + 10, MOD);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      dp[i] = min(dp[i], ps[i - 1] + m - j + mn[j][mask[i][j]]);
    }
    for (int j = 0; j <= m; j++) {
      mn[j][rmask[i - 1][j]] = min(mn[j][rmask[i - 1][j]], dp[i] - ps[i]);
    }
  }
  int ans = ps[n];
  for (int i = 1; i <= n; i++) {
    ans = min(ans, dp[i] - ps[i] + ps[n]);
  }
  printf("%d\n", ans);
  return 0;
}
