#include <bits/stdc++.h>
using namespace std;
int p[21], d[2100200], a[200200], n, m, b[200200], h = 0;
string s[200200];
void pre(void) {
  p[0] = 1;
  for (int i = 1; i < 21; ++i) p[i] = p[i - 1] << 1;
}
void read(void) {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> s[i];
  m = s[0].length();
  b[0] = m;
  for (int i = 1; i < n; ++i)
    for (int j = m; j >= 0; --j)
      if (s[i - 1].substr(m - j, j) == s[i].substr(0, j)) {
        b[i] = m - j;
        break;
      }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) a[i] += (s[i][j] == '1' ? p[j] : 0);
}
void kill(void) {
  for (int i = 0; i < 2100200; ++i) d[i] = 2100200;
  d[1] = 0;
  h += m;
  for (int i = 1; i < n; ++i) {
    h += b[i];
    int x = m + 1;
    for (int j = 0; j <= m; ++j)
      x = min(x, d[(a[i] & (p[j] - 1)) | p[j]] + m - j);
    x -= b[i];
    for (int j = 0; j <= m; ++j) {
      int to = (a[i - 1] >> (m - j)) | p[j];
      d[to] = min(d[to], x);
    }
  }
  cout << *min_element(d, d + 2100200) + h << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  pre();
  read();
  kill();
  return 0;
}
