#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
int st[maxn];
int lcp[maxn];
int tmp[21][1 << 21];
int res, n, m;
char buf[25];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", buf);
    for (int j = 0; buf[j]; j++) st[i] = st[i] * 2 + buf[j] - '0';
  }
  m = strlen(buf);
  for (int i = 1; i + 1 <= n; i++)
    for (int j = 1; j <= m; j++)
      if ((st[i] & ((1 << j) - 1)) == (st[i + 1] >> (m - j))) lcp[i] = j;
  for (int i = 1; i <= n; i++) lcp[i] += lcp[i - 1];
  res = n * m - lcp[n];
  for (int i = 0; i <= m; i++)
    for (int j = 0; j < (1 << i); j++) tmp[i][j] = -1000000000;
  for (int i = 1; i < n; i++) {
    int now = lcp[i - 1];
    for (int j = 0; j <= m; j++)
      now = max(now, lcp[i - 1] + j + tmp[j][st[i + 1] >> (m - j)]);
    res = min(res, n * m - now - lcp[n - 1] + lcp[i]);
    if (res == 15) printf("\n");
    for (int j = 1, k = 0; j <= (1 << m); j *= 2, k++)
      tmp[k][st[i] & (j - 1)] = max(tmp[k][st[i] & (j - 1)], now - lcp[i]);
  }
  printf("%d\n", res);
}
