#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int maxn = ((1 << 20) + 1000);
int dp[21][((1 << 20) + 1000)], n, ans, len;
int a[((1 << 20) + 1000)];
char str[21 + 10];
int main() {
  scanf("%d", &n);
  len = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str);
    if (len == 0) len = strlen(str);
    for (int j = 0; j < len; ++j) {
      a[i] = (a[i] << 1) + str[j] - '0';
    }
  }
  ans = len;
  memset(dp, 62, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 2, j, maxx, k; i <= n; ++i) {
    for (j = len; j; --j)
      if ((a[i - 1] & ((1 << j) - 1)) == (a[i] >> (len - j))) break;
    ans += (k = len - j), maxx = 214748364;
    for (j = 0; j <= len; ++j) maxx = min(maxx, dp[len - j][a[i] >> j] + j);
    for (j = 0; j <= len; ++j)
      dp[j][a[i - 1] & ((1 << j) - 1)] =
          min(dp[j][a[i - 1] & ((1 << j) - 1)], maxx - k);
  }
  int tt = 214748364;
  for (int i = 0; i <= len; ++i) {
    for (int j = 0; j < 1 << i; ++j) tt = min(tt, dp[i][j]);
  }
  cout << ans + tt << endl;
  return 0;
}
