#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 10;
const long long MAXS = 21;
const long long INF = 1e9 + 10;
int lps[MAXN][MAXS];
int fa[MAXN][MAXS][2];
int e[MAXS][(1 << MAXS)];
int dp[MAXN];
char s[MAXN][MAXS];
int main() {
  int n, res = 0, t = 0;
  scanf("%d", &n);
  for (int i = 0; i < MAXS; i++) {
    for (int j = 0; j < (1 << MAXS); j++) {
      e[i][j] = -INF;
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%s", &s[i][0]);
    if (i == 1) {
      for (int j = 0; j < strlen(s[i]); j++) {
        s[0][j] = '2';
      }
    }
    int w = 0, x = 0, k = 0;
    for (int j = 0; j <= strlen(s[i]); j++) {
      w = max(w, e[j][x] + j);
      if (j < strlen(s[i])) {
        x *= 2;
        x += (s[i][j] - '0');
      }
    }
    for (int j = 2; j <= strlen(s[i]); j++) {
      lps[i][j] = lps[i][j - 1];
      while (lps[i][j] > 0 && s[i][j - 1] != s[i][lps[i][j]]) {
        lps[i][j] = lps[i][lps[i][j]];
      }
      if (s[i][lps[i][j]] == s[i][j - 1]) {
        lps[i][j]++;
      }
    }
    for (int j = 0; j <= strlen(s[i]); j++) {
      for (int u = 0; u < 2; u++) {
        if (j != strlen(s[i]) && s[i][j] - '0' == u) {
          fa[i][j][u] = j + 1;
        } else {
          fa[i][j][u] = fa[i][lps[i][j]][u];
        }
      }
    }
    if (i == 1) {
      k = 0;
    } else {
      for (int j = 0; j < strlen(s[i - 1]); j++) {
        k = fa[i][k][s[i - 1][j] - '0'];
      }
    }
    dp[i - 1] = w - k;
    t += k;
    if (i == 1) {
      e[0][0] = max(e[0][0], dp[0]);
    } else {
      x = 0;
      e[0][0] = max(e[0][0], dp[i - 1]);
      for (int j = strlen(s[i - 1]) - 1; j >= 0; j--) {
        x += (1 << (strlen(s[i - 1]) - j - 1)) * (s[i - 1][j] - '0');
        e[(strlen(s[i - 1]) - j)][x] =
            max(e[(strlen(s[i - 1]) - j)][x], dp[i - 1]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    res = max(res, dp[i] + t);
  }
  printf("%d", n * strlen(s[0]) - res);
}
