#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int M = 1000;
const int inf = 1e9 + 7;
const long long base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;
int a[N];
int dp[1 << 21];
int n;
int m;
int main() {
  scanf("%d", &n);
  string s;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    a[i] = 0;
    for (int j = 0; j < s.size(); j++) a[i] = a[i] * 2 + s[j] - '0';
  }
  m = s.size();
  for (int mask = (int)0; mask < (int)1 << 21; mask++) dp[mask] = m;
  int tol = m;
  dp[0] = 0;
  for (int i = 2; i <= n; i++) {
    int cost = 0;
    for (; (a[i - 1] & (1 << m - cost) - 1) != (a[i] >> cost); cost++)
      ;
    tol += cost;
    int cur = inf;
    for (int j = 0; j <= m; j++)
      cur = min(cur, dp[((1 << (m - j))) | (a[i] >> j)] + j);
    cur -= cost;
    for (int j = 0; j <= m; j++) {
      int nw = ((1 << j) | (a[i - 1] & (1 << j) - 1));
      dp[nw] = min(dp[nw], cur);
    }
  }
  int ans = 0;
  for (int mask = (int)0; mask < (int)1 << 21; mask++) ans = min(ans, dp[mask]);
  cout << tol + ans << endl;
}
