#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, inf = 1e9;
int n, m, a[N], f[21][1 << 21], ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    string s;
    cin >> s;
    m = s.size();
    for (int j = 0; j < m; ++j) {
      a[i] = a[i] * 2 + (s[j] - '0');
    }
  }
  for (int i = 0; i < 21; ++i) {
    for (int mask = 0; mask < (1 << 21); ++mask) {
      f[i][mask] = inf;
    }
  }
  f[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    int rem = 0;
    if (i == 1)
      rem = 0;
    else {
      for (int j = 0; j <= m; ++j)
        if ((a[i] >> (m - j)) == (a[i - 1] & ((1 << j) - 1))) rem = j;
    }
    rem = m - rem;
    ans += rem;
    int rem2 = inf;
    for (int j = 0; j <= m; ++j) {
      rem2 = min(rem2, f[m - j][a[i] >> j] + j);
    }
    if (i > 1)
      for (int j = 0; j <= m; ++j) {
        f[j][a[i - 1] & ((1 << j) - 1)] =
            min(f[j][a[i - 1] & ((1 << j) - 1)], rem2 - rem);
      }
  }
  int minn = inf;
  for (int i = 0; i < 21; ++i) {
    for (int mask = 0; mask < (1 << 21); ++mask) {
      minn = min(minn, f[i][mask]);
    }
  }
  cout << ans + minn;
  return 0;
}
