#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10, inf = (1 << 30) + 7, maxk = 100 + (1 << 20),
          ne = 1 << 20;
int d[25][maxk], n, m, cur, dp[maxn];
char s[maxn][25];
inline void upd(int first, int a) {
  d[0][0] = ((d[0][0]) < (a) ? (d[0][0]) : (a));
  int c = 0, second = 1;
  for (int i = m - 1; i > -1; i--) {
    c += second * (s[first][i] - '0');
    second <<= 1;
    d[m - i][c] = ((d[m - i][c]) < (a) ? (d[m - i][c]) : (a));
  }
}
inline int diff(int first, int second) {
  int c = 0, z = 1, d = 0;
  int e = 0;
  int j = 0;
  for (int i = m - 1; i > -1; i--) {
    c += z * (s[first][i] - '0');
    z <<= 1;
    d = 2 * d + (s[second][j] - '0');
    ++j;
    if (c == d) e = j;
  }
  return e;
}
inline int mini(int first) {
  int ans = inf;
  int c = 0;
  for (int i = 0; i < m + 1; i++) {
    ans = ((ans) < (d[i][c] + m - i) ? (ans) : (d[i][c] + m - i));
    c = 2 * c + (s[first][i] - '0');
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  gets(s[0]);
  fill(&d[0][0], &d[0][0] + 25 * maxk, inf);
  fill(dp, dp + maxn, inf);
  for (int i = 0; i < n; i++) gets(s[i]);
  m = strlen(s[0]);
  dp[0] = m;
  int ans = inf;
  cur = m;
  if (n == 1) {
    cout << m << "\n";
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int dif = diff(i - 1, i);
    int xx = cur + m - dif;
    dp[i] = mini(i) + cur;
    dp[i] = ((dp[i]) < (cur + m) ? (dp[i]) : (cur + m));
    upd(i - 1, dp[i] - xx);
    dp[i] = ((dp[i]) < (dp[i - 1] + m - dif) ? (dp[i]) : (dp[i - 1] + m - dif));
    cur = xx;
  }
  printf("%d\n", dp[n - 1]);
}
