#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
const int S = 1048576 + 10;
int n, f[N], g[23][S], v[23][S], e[23], a[N], len[N], minn;
char buf[23];
string str[N];
inline int Trans1(int k, int l) { return (a[k] >> (len[k] - l)); }
inline int Trans2(int k, int l) { return a[k] % e[l]; }
int F(int k1, int k2) {
  int l = min(len[k1], len[k2]);
  for (int i = l; i >= 1; i--)
    if (Trans2(k1, i) == Trans1(k2, i)) return len[k2] - i;
  return len[k2];
}
void DP() {
  memset(v, -1, sizeof(v));
  for (int i = 2; i <= n; i++) {
    int l = len[i];
    f[i] = l - F(i - 1, i) + minn;
    for (int j = 1; j <= l; j++) {
      int t = Trans1(i, j);
      if (v[j][t] == -1) continue;
      f[i] = min(f[i], g[j][t] + l - j - F(i - 1, i));
    }
    for (int j = 1; j <= len[i - 1]; j++) {
      int t = Trans2(i - 1, j);
      if (v[j][t] == -1 || f[i] < g[j][t]) v[j][t] = 1, g[j][t] = f[i];
    }
    minn = min(minn, f[i]);
  }
  int ans = len[1], ret = 0;
  for (int i = 2; i <= n; i++) ans += F(i - 1, i), ret = min(ret, f[i]);
  printf("%d\n", ans + ret);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", buf);
    str[i] = buf;
    len[i] = str[i].size();
    for (int j = 0; j < str[i].size(); j++)
      a[i] = a[i] * 2 + int(str[i][j] - '0');
  }
  e[0] = 1;
  for (int i = 1; i < 23; i++) e[i] = e[i - 1] * 2;
  DP();
  return 0;
}
