#include <bits/stdc++.h>
using namespace std;
const int M = 20, N = 200001;
int n, m, a[N], f[M + 1][1 << M];
char s[M + 1];
int Cal(int x, int y) {
  for (int i = 0; i < m; ++i)
    if ((x & ((1 << (m - i)) - 1)) == (y >> i)) return i;
  return m;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    for (m = 0; s[m]; ++m) a[i] = a[i] << 1 | (s[m] == '1');
  }
  for (int i = 1; i < m + 1; ++i)
    for (int j = 0; j < 1 << i; ++j) f[i][j] = m;
  int sum = m;
  for (int i = 1; i < n; ++i) {
    int cost = Cal(a[i - 1], a[i]);
    sum += cost;
    int Min = 1 << 30;
    for (int j = 0; j < m + 1; ++j)
      Min = min(Min, f[j][a[i] >> (m - j)] + m - j - cost);
    for (int j = 0; j < m + 1; ++j) {
      int t = a[i - 1] & ((1 << j) - 1);
      f[j][t] = min(f[j][t], Min);
    }
  }
  int ans = sum;
  for (int i = 1; i < m + 1; ++i)
    for (int j = 0; j < 1 << i; ++j) ans = min(ans, sum + f[i][j]);
  printf("%d\n", ans);
  return 0;
}
