#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int mask1[21], mask2[21], a[200000], f[200000];
int getWeight(int a, int b, int l) {
  for (int i = l; i >= 0; i--)
    if ((a & mask1[i]) == ((b & mask2[i]) >> l - i)) return l - i;
}
int main() {
  int n, l;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    a[i] = 0;
    char tmp[21];
    scanf("%s", tmp);
    l = strlen(tmp);
    for (int j = 0; j < l; j++) a[i] = a[i] * 2 + tmp[j] - '0';
  }
  for (int i = 0; i <= l; i++) {
    mask1[i] = mask2[i] = 0;
    for (int j = 0; j < i; j++) mask1[i] += 1 << j;
    for (int j = l - i; j < l; j++) mask2[i] += 1 << j;
  }
  int sum = 0;
  for (int i = 1; i < n; i++) sum += getWeight(a[i - 1], a[i], l);
  vector<vector<int> > minv;
  minv.resize(l + 1);
  for (int i = 0; i <= l; i++) minv[i].assign(1 << i, inf);
  int ans = -l;
  for (int i = 1; i < n; i++) {
    f[i] = 0;
    for (int j = 0; j <= l; j++) {
      int tmp = (a[i] & mask2[j]) >> l - j;
      f[i] = min(f[i], minv[j][tmp] + l - j);
    }
    f[i] -= getWeight(a[i - 1], a[i], l);
    ans = min(ans, f[i]);
    for (int j = 0; j <= l; j++) {
      int tmp = a[i - 1] & mask1[j];
      minv[j][tmp] = min(minv[j][tmp], f[i]);
    }
  }
  printf("%d\n", ans + sum + l * 2);
  return 0;
}
