#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int maxm = 1e7 + 10;
const int inf = 1e9 + 7;
int trie[maxm][2], fail[maxm], dp[maxm];
int zcy[maxn], n, len, ptr = 1, allsum, pre[maxn];
char mem[maxm], *str[maxn], dep[maxn];
int get(int x, int y) {
  int ans = len;
  return ans;
}
void build() {
  int l = 0, r = 0;
  dp[r++] = 1, fail[1] = 0;
  while (l < r) {
    int u = dp[l++];
    for (int i = 0; i < 2; ++i)
      if (trie[u][i]) {
        int v = trie[u][i];
        if (u == 1) {
          fail[v] = 1;
        } else {
          int fu = fail[u];
          while (fu != 1 && !trie[fu][i]) fu = fail[fu];
          if (trie[fu][i])
            fail[v] = trie[fu][i];
          else
            fail[v] = 1;
        }
        dp[r++] = v;
      }
  }
}
int main() {
  scanf("%d", &n);
  str[1] = mem, dep[1] = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str[i]);
    if (i == 1) len = strlen(str[i]);
    str[i + 1] = str[i] + strlen(str[i]);
    int rt = 1;
    for (char* j = str[i + 1] - 1; j >= str[i]; --j) *j -= '0';
    for (char* j = str[i + 1] - 1; j >= str[i]; --j) {
      if (!trie[rt][*j]) trie[rt][*j] = ++ptr, dep[ptr] = dep[rt] + 1;
      rt = trie[rt][*j];
    }
    zcy[i] = rt;
  }
  build();
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 2; i <= n; ++i) {
    int rt = 1;
    dp[rt] = len, pre[i] = len;
    for (char* j = str[i] - 1; j >= str[i - 1]; --j)
      rt = trie[rt][*j], dp[rt] = len - dep[rt];
    for (int k = zcy[i]; k; k = fail[k]) pre[i] = min(pre[i], dp[k]);
    rt = 1;
    for (char* j = str[i] - 1; j >= str[i - 1]; --j)
      rt = trie[rt][*j], dp[rt] = inf;
  }
  memset(dp, 0x3f, sizeof(dp));
  dp[1] = len, allsum = 0;
  for (int i = 2; i <= n; ++i) {
    int mn = inf, rt = 1;
    for (int k = zcy[i]; k; k = fail[k])
      mn = min(mn, dp[k] + allsum + len - dep[k]);
    allsum += pre[i];
    dp[rt] = min(dp[rt], mn - allsum);
    for (char* j = str[i] - 1; j >= str[i - 1]; --j)
      rt = trie[rt][*j], dp[rt] = min(dp[rt], mn - allsum);
  }
  int ans = inf;
  for (int i = 1; i <= ptr; ++i) ans = min(ans, dp[i] + allsum);
  printf("%d", ans);
}
