#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 20) + 1;
int n, m, dp[MAXN], psum[MAXN], best[21][MAXN];
string arr[MAXN];
int get_(int l, int r) {
  for (int i = m; i; i--)
    if (arr[l].substr(m - i, i) == arr[r].substr(0, i)) return i;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    m = arr[i].size();
    if (i)
      psum[i] = psum[i - 1] + m - get_(i - 1, i);
    else
      psum[i] = m;
  }
  memset(best, -1, sizeof(best));
  memset(dp, 63, sizeof(dp));
  int answer = 1e9;
  for (int i = 1; i < n; i++) {
    int mask = 0;
    dp[i] = psum[i - 1] + m;
    for (int j = 0; j <= m; j++) {
      mask <<= 1;
      if (j) mask += arr[i][j - 1] - '0';
      int id = best[j][mask];
      if (~id) dp[i] = min(dp[i], dp[id] + psum[i - 1] - psum[id] + m - j);
    }
    mask = 0;
    for (int j = 0; j <= m; j++) {
      if (j) mask |= (arr[i - 1][m - j] - '0') << (j - 1);
      int id = best[j][mask];
      if (!(~id) || (dp[id] + psum[i] - psum[id]) > dp[i]) best[j][mask] = i;
    }
    answer = min(answer, dp[i] + psum[n - 1] - psum[i]);
  }
  cout << min(answer, psum[n - 1]) << endl;
  return 0;
}
