#include <bits/stdc++.h>
using namespace std;
int n;
string st;
int m;
int ar[1 << 20];
int dp[22][1 << 21];
int add_all;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> st;
    m = st.size();
    for (int j = 0; j < st.size(); j++) {
      ar[i] = ar[i] * 2 + st[j] - 48;
    }
  }
  for (int i = 0; i <= 20; i++)
    for (int j = 0; j <= (1 << m); j++) dp[i][j] = 1e9;
  add_all = m;
  dp[0][0] = 0;
  for (int i = 2; i <= n; i++) {
    int memo = add_all;
    int F = 0;
    for (int j = m; j; --j) {
      if ((ar[i] >> (m - j)) == (ar[i - 1] & ((1 << j) - 1))) {
        F = j;
        break;
      }
    }
    add_all += m - F;
    int bst = 1e9;
    for (int j = 0; j <= m; j++) {
      bst = min(bst, dp[j][ar[i] >> (m - j)] + (m - j));
    }
    for (int j = 0; j <= m; j++) {
      int tail = (ar[i - 1] & ((1 << j) - 1));
      dp[j][tail] = min(dp[j][tail], bst + (memo - add_all));
    }
  }
  int ans = 1e9;
  for (int i = 0; i <= m; i++)
    for (int j = 0; j < (1 << m); j++) ans = min(ans, dp[i][j]);
  cout << ans + add_all << endl;
  return 0;
}
