#include <bits/stdc++.h>
using namespace std;
int L, n, a[200005][25], s[200005], dp[25][1 << 20];
char ch[30];
int cost(int x, int y) {
  int t1 = s[x], t2 = s[y];
  for (int i = L; i >= 0; --i) {
    if (t1 == t2) return i;
    t2 >>= 1;
    t1 -= a[x][L - i + 1] * (1 << (i - 1));
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", ch + 1);
    L = strlen(ch + 1);
    for (int j = 1; j <= L; ++j) {
      a[i][j] = ch[j] - '0';
      s[i] = (s[i] << 1) + a[i][j];
    }
  }
  memset(dp, 60, sizeof dp);
  dp[0][0] = 0;
  int base = L;
  for (int i = 1; i <= n - 1; ++i) {
    int tmp = L - cost(i, i + 1), now = 0, mx = 0x3f3f3f3f;
    base += tmp;
    for (int j = 0; j <= L; ++j) {
      now = (now << 1) + a[i + 1][j];
      mx = min(mx, dp[j][now] + L - j);
    }
    now = 0;
    for (int j = 0; j <= L; ++j) {
      dp[j][now] = min(dp[j][now], mx - tmp);
      now += a[i][L - j] * (1 << j);
    }
  }
  int ans = 0;
  for (int i = 0; i <= L; ++i)
    for (int j = 0; j <= (1 << i) - 1; ++j) ans = min(ans, dp[i][j]);
  printf("%d\n", ans + base);
  return 0;
}
