#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const int maxn = 2e5 + 10, maxm = 2e4 + 10, lg = 21, mod = 1e9 + 7, inf = 1e18;
int n, k, a[maxn], dp[maxn], laz, mn[(1 << lg)][lg];
void mini(int &x, int y) {
  if (x > y) x = y;
}
int f(int a, int b) {
  int x = 0, y = 0, ret = 0;
  for (int i = 0; i < k; i++)
    if ((x ^= ((a >> (k - i - 1) & 1) << i)) == (y = y * 2 + (b >> i & 1)))
      ret = max(ret, (int)i + 1);
  return ret;
}
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;
    k = (int)(s.size());
    for (int j = 0; j < k; j++) a[i] += (s[j] - '0') << j;
  }
  memset(dp, 69, sizeof(dp)), memset(mn, 69, sizeof(mn));
  dp[0] = mn[0][0] = k;
  for (int i = 2; i <= n; i++) {
    for (int j = 0, mask = 0; j <= k; j++)
      mini(dp[i - 1], mn[mask][j] + laz + k - j),
          mask = mask * 2 + (a[i] >> j & 1);
    dp[i - 1] -= (laz += k - f(a[i - 1], a[i]));
    for (int j = 0, mask = 0; j <= k; j++)
      mini(mn[mask][j], dp[i - 1]), mask ^= (a[i - 1] >> (k - j - 1) & 1) << j;
  }
  int ans = inf;
  for (int i = 0; i < n; i++) mini(ans, dp[i]);
  cout << ans + laz;
  return 0;
}
