#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);
int weight(int n, int x, int y) {
  for (int i = n; i >= 1; i--)
    if ((x & ((1 << i) - 1)) == (y >> (n - i))) return n - i;
  return n;
}
int main() {
  int n, m;
  cin >> n;
  static int a[200000];
  for (int i = 0; i < n; i++) {
    char c;
    while (c = getchar(), c != '0' && c != '1')
      ;
    m = a[i] = 0;
    while (c == '0' || c == '1') {
      m++;
      a[i] = a[i] * 2 + (c == '1');
      c = getchar();
    }
  }
  if (n == 1) return cout << m, 0;
  static int dp[21][1048576];
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < (1 << i); j++) dp[i][j] = m;
  int sum = m;
  for (int i = 1; i < n; i++) {
    int tmp = weight(m, a[i - 1], a[i]);
    sum += tmp;
    int mn = INF;
    for (int j = 0; j <= m; j++)
      mn = min(mn, dp[j][a[i] >> (m - j)] + m - j - tmp);
    for (int j = 0; j <= m; j++) {
      int x = a[i - 1] & ((1 << j) - 1);
      dp[j][x] = min(dp[j][x], mn);
    }
  }
  int ans = INF;
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < (1 << i); j++) ans = min(ans, sum + dp[i][j]);
  cout << ans;
  return 0;
}
