#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ '0');
    ch = getchar();
  }
  return x * f;
}
int n, m, a[1000005];
inline int read_bin() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    ch = getchar();
  }
  int cnt = 0;
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (ch ^ '0');
    cnt++;
    ch = getchar();
  }
  m = cnt;
  return x;
}
inline int pre(int x, int len) { return x >> (m - len); }
inline int suf(int x, int len) { return x & ((1 << len) - 1); }
inline int Same(int x, int y) {
  for (register int i = m; i; --i) {
    if (suf(x, i) == pre(y, i)) return i;
  }
  return 0;
}
int dp[21][1 << 20];
int main() {
  n = read();
  for (register int i = 1; i <= n; ++i) a[i] = read_bin();
  int sum = 0;
  memset(dp, 0x3f, sizeof(dp)), dp[0][0] = m;
  for (register int i = 2; i <= n; ++i) {
    int len = Same(a[i - 1], a[i]);
    sum += m - len;
    int mino = 0x3f3f3f3f;
    for (register int j = 0; j <= m; ++j) {
      mino = min(mino, dp[j][pre(a[i], j)] + len - j);
    }
    for (register int j = 0; j <= m; ++j) {
      int now = suf(a[i - 1], j);
      dp[j][now] = min(dp[j][now], mino);
    }
  }
  printf("%d\n", dp[0][0] + sum);
}
