#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
const int INF = 1000 * 1000 * 100;
string s[N];
char ch[30];
int d[1000 * 3000 + 10], l[30], r[30];
int lcps(int x) {
  int sz = s[x].size();
  for (int i = sz - 1; i >= 0; i--)
    r[i] = r[i + 1] + ((s[x][i] - '0') << (sz - i - 1));
  l[0] = s[x + 1][0] - '0';
  for (int i = 1; i < sz; i++) l[i] = l[i - 1] * 2 + (s[x + 1][i] - '0');
  for (int i = sz; i > 0; i--)
    if (l[i - 1] == r[sz - i]) return i;
  return 0;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%20s", ch);
    for (int j = 0; j < 20 && (ch[j] == '0' || ch[j] == '1'); j++)
      s[i] += ch[j];
  }
  int sz = s[0].size(), p = (1 << (sz + 1)), all(0), tmp(0);
  fill(d, d + p, INF);
  d[p - 1] = 0;
  for (int i = 0; i < n; i++) {
    int t = sz, mn = INF, z;
    if (i) {
      t = lcps(i - 1);
      for (int j = 0; j <= sz; j++) {
        if (j == 0) {
          mn = min(all + sz - tmp, mn);
          if (s[i][0] == '0')
            z = p - 2;
          else
            z = 1;
        } else {
          mn = min(d[z] + sz - j, mn);
          z *= 2;
          if (j < sz) z += s[i][j] - '0';
          z %= p;
        }
      }
      z = 0;
      mn -= (sz - t);
      d[p - 1] = min(d[p - 1], mn);
      for (int j = sz - 1; j >= 0; j--) {
        int v = (1 << (sz - j - 1));
        if (s[i - 1][j] - '0' == 1) {
          z &= ((1 << (sz - j)) - 1);
          if ((z & v) == 0) z += v;
        } else {
          z |= ((p - 1) ^ ((1 << (sz - j)) - 1));
          if ((z & v) != 0) z -= v;
        }
        d[z] = min(d[z], mn);
      }
      tmp += (sz - t);
      all += (sz - t);
      all = min(all, mn + tmp);
    } else
      all += sz, tmp += sz, d[p - 1] = sz;
  }
  cout << all << endl;
  return 0;
}
