#include <bits/stdc++.h>
using namespace std;
int n, m;
long long k;
bool debug = false;
char s[22];
int len, a[200005], sum[200005], dp[21][1 << 20];
int dis(int i, int j) {
  for (int x = len; x >= 0; x--) {
    if ((a[i] & ((1 << x) - 1)) == a[j] >> (len - x)) {
      return len - x;
    }
  }
  return len;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    len = (int)strlen(s);
    for (int j = 0; j < len; j++) {
      a[i] |= (s[j] - '0') << (len - j - 1);
    }
  }
  sum[1] = len;
  for (int i = 2; i <= n; i++) sum[i] = sum[i - 1] + dis(i - 1, i);
  memset(dp, 63, sizeof dp);
  dp[0][0] = 0;
  for (int i = 2; i <= n; i++) {
    int mm = 2147483647;
    for (int j = 0; j <= len; j++) {
      mm = min(mm, dp[j][a[i] >> (len - j)] + len - j);
    }
    mm += sum[i - 1];
    for (int j = 0; j <= len; j++) {
      dp[j][a[i - 1] % (1 << j)] = min(dp[j][a[i - 1] % (1 << j)], mm - sum[i]);
    }
  }
  int ans = 2147483647;
  for (int i = 0; i <= len; i++)
    for (int j = 0; j < (1 << i); j++) ans = min(ans, dp[i][j] + sum[n]);
  printf("%d\n", ans);
  return 0;
}
