#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  if (p1 == p2) {
    p2 = (p1 = buf) + fread(buf, 1, 100000, stdin);
    if (p1 == p2) return EOF;
  }
  return *p1++;
}
inline void read(int &x) {
  char c = nc(), b = 1;
  for (; !(c >= '0' && c <= '9'); c = nc())
    if (c == '-') b = -1;
  for (x = 0; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
  x *= b;
}
inline int read(char *s) {
  int len = 0;
  char c = nc();
  for (; !(c >= '0' && c <= '1'); c = nc())
    ;
  for (; c >= '0' && c <= '1'; s[++len] = c, c = nc())
    ;
  s[++len] = 0;
  return len - 1;
}
const int N = 200005;
const int M = 20;
int n, all, len;
int a[N];
int f[M + 1][1 << M];
int calc(int x, int y) {
  for (int i = len; i; i--)
    if (((x) & ((1 << (i)) - 1)) == ((y) >> (len - (i)))) return i;
  return 0;
}
int main() {
  char tmp[M];
  read(n);
  for (int i = 1; i <= n; i++) {
    len = read(tmp);
    for (int j = 1; j <= len; j++) a[i] = (a[i] << 1) + tmp[j] - '0';
  }
  memset(f, 0x3f, sizeof(f));
  f[0][0] = len;
  for (int i = 2; i <= n; i++) {
    int x = len - calc(a[i - 1], a[i]);
    all += x;
    int minimum = 1 << 30;
    for (int j = len; ~j; j--)
      minimum = min(minimum, f[j][((a[i]) >> (len - (j)))] + len - j - x);
    for (int j = len; ~j; j--)
      f[j][((a[i - 1]) & ((1 << (j)) - 1))] =
          min(f[j][((a[i - 1]) & ((1 << (j)) - 1))], minimum);
  }
  printf("%d\n", f[0][0] + all);
  return 0;
}
