#include <bits/stdc++.h>
using namespace std;
string a[200009];
int pre[1 << 20][22], cost[200009], n, m, dp[200009];
int compute(string suf, string pre) {
  for (int k = int(0); k <= int(m - 1); k++) {
    int j = k, i = 0;
    while (j < m) {
      if (suf[j] == pre[i]) {
        j++;
        i++;
      } else
        break;
    }
    if (j == m) return k;
  }
  return m;
}
int calmask(string str, int len) {
  int mask = 0;
  for (int i = int(m - len); i <= int(m - 1); i++) {
    mask = mask * 2;
    if (str[i] == '1') mask++;
  }
  return mask;
}
int calmask2(string str, int len) {
  int mask = 0;
  for (int i = int(0); i <= int(len - 1); i++) {
    mask = mask * 2;
    if (str[i] == '1') mask++;
  }
  return mask;
}
int main() {
  std::ios::sync_with_stdio(false);
  int ans;
  cin >> n;
  for (int i = int(1); i <= int(n); i++) cin >> a[i];
  m = a[1].length();
  for (int i = int(0); i <= int((1 << m) - 1); i++)
    for (int j = int(0); j <= int(m); j++) pre[i][j] = 2000000000;
  cost[0] = 0;
  for (int i = int(1); i <= int(n - 1); i++)
    cost[i] = cost[i - 1] + compute(a[i], a[i + 1]);
  pre[0][0] = cost[n - 1];
  ans = 2000000000;
  for (int i = int(n); i >= int(1); i--) {
    int mini = 2000000000;
    int mask = 0;
    for (int j = int(0); j <= int(m); j++) {
      if (i == 1 && j > 0) break;
      mini = min(mini, pre[mask][j] + m - j);
      if (m - j - 1 >= 0 && a[i - 1][m - j - 1] == '1') mask |= (1 << j);
    }
    mini = mini - cost[i - 1];
    dp[i] = mini;
    if (i - 2 >= 0) {
      mask = 0;
      for (int j = int(0); j <= int(m); j++) {
        pre[mask][j] = min(pre[mask][j], mini + cost[i - 2]);
        mask *= 2;
        if (j < m && a[i][j] == '1') mask++;
      }
    }
  }
  cout << dp[1] << endl;
  return 0;
}
