#include <bits/stdc++.h>
int arr[2000005], dp[21][2000005], len;
char str[25];
inline 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() {
  int n;
  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);
  int lazy = 0;
  memset(dp, 0x3f, sizeof(dp));
  dp[0][0] = len;
  for (int i = 1; i < n; i++) {
    int x = len - calc(arr[i - 1], arr[i]), res = 1e9;
    for (int j = 0; j <= len; j++)
      (res) = std::min(res, dp[j][arr[i] >> len - j] + len - j + lazy);
    lazy += x;
    for (int j = 0; j <= len; j++)
      (dp[j][arr[i - 1] & (1 << j) - 1]) =
          std::min(dp[j][arr[i - 1] & (1 << j) - 1], res - lazy);
  }
  printf("%d\n", dp[0][0] + lazy);
  return 0;
}
