#include <bits/stdc++.h>
using namespace std;
vector<int> getv[30];
int n, m, val[200010], csum[200010], dp[200010];
int prefix(int id, int len) { return val[id] >> (m - len); }
int suffix(int id, int len) { return val[id] & ((1 << len) - 1); }
void preprocess() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    char s[30];
    scanf("%s", s);
    for (int j = val[i] = 0; s[j]; j++) val[i] = val[i] * 2 + s[j] - '0';
    m = strlen(s);
  }
  for (int i = 0; i <= m; i++) getv[i].resize(1 << i, -1);
  csum[0] = 0;
  csum[1] = m;
  for (int i = 2; i <= n; i++) {
    csum[i] = csum[i - 1] + m;
    for (int j = 1; j <= m; j++)
      if (prefix(i, j) == suffix(i - 1, j)) csum[i] = csum[i - 1] + m - j;
  }
  csum[n + 1] = csum[n];
}
int get_min_cost(int id) {
  int ret = 999999999;
  for (int l = 0; l <= m; l++) {
    int pos = getv[l][prefix(id, l)];
    if (pos == -1) continue;
    ret = min(ret, dp[pos] + csum[id - 1] - csum[pos + 1] + m - l);
  }
  return ret;
}
void update(int id, int v) {
  dp[id] = v;
  for (int l = 0; l <= m; l++) {
    int& pos = getv[l][suffix(id, l)];
    if (pos == -1 || dp[pos] + csum[id + 1] - csum[pos + 1] > dp[id]) pos = id;
  }
}
void solution() {
  getv[0][0] = 0;
  dp[0] = m;
  for (int i = 2; i <= n; i++) {
    int min_cost = get_min_cost(i);
    update(i - 1, min_cost);
  }
  int ans = 999999999;
  for (int i = 0; i < n; i++) ans = min(ans, dp[i] + csum[n] - csum[i + 1]);
  printf("%d\n", ans);
}
int main() {
  preprocess();
  solution();
}
