#include <bits/stdc++.h>
using namespace std;
int arr[200005], dp[21][2000005], len;
char str[25];
inline void upd(int &x, int y) {
  if (x > y) x = y;
}
inline int chk(int x, int y) {
  for (int i = len; i >= 0; i--) {
    if ((x & (1 << i) - 1) == (y >> len - i)) return i;
  }
  return -1;
}
int main() {
  int n, lazy = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    for (int j = 0; str[j]; j++) arr[i] = arr[i] << 1 | str[j] - '0';
  }
  len = strlen(str);
  memset(dp, 0x3f, sizeof(dp));
  dp[0][0] = len;
  for (int i = 1; i < n; i++) {
    int x = len - chk(arr[i - 1], arr[i]), cur = 1e9;
    for (int j = len; j >= 0; j--)
      upd(cur, dp[j][arr[i] >> (len - j)] + len - j + lazy);
    lazy += x;
    for (int j = len; j >= 0; j--)
      upd(dp[j][arr[i - 1] & (1 << j) - 1], cur - lazy);
  }
  printf("%d\n", dp[0][0] + lazy);
  return 0;
}
