#include <bits/stdc++.h>
using namespace std;
vector<int> G[2 * 100000 + 5];
int mq[(1 << 21) + 4];
int off;
string S[200000 + 5];
int A[200000 + 5];
int dp[200000 + 5];
int N, M;
int consecIntrsx[200000 + 5];
int prefix[200000 + 5];
int extractRear(int x, int bit) { return (x & ((1 << bit) - 1)) | (1 << bit); }
int extractFront(int x, int bit) { return (x >> (M - bit)) | (1 << bit); }
int intersection(int x, int y) {
  if (x == 0 or y == 0 or x == N + 1 or y == N + 1) return 0;
  for (int i = M; i >= 0; --i) {
    if (extractRear(A[x], i) == extractFront(A[y], i)) {
      return i;
    }
  }
}
int rangeQuery(int i, int j) {
  int len = (j - i + 1);
  return M * len - prefix[j] + prefix[i - 1];
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> S[i];
    A[i] = 0;
    for (int j = 0; j < S[i].size(); ++j) {
      A[i] = A[i] * 2 + (S[i][j] == '1');
    }
  }
  M = S[1].size();
  for (int i = 1; i <= N; ++i) {
    consecIntrsx[i] = intersection(i - 1, i);
    prefix[i] = prefix[i - 1] + consecIntrsx[i];
  }
  dp[1] = M;
  for (int j = 0; j <= 1 << (M + 1); ++j) mq[j] = 1000000007;
  for (int i = 2; i <= N; ++i) {
    dp[i] = M + rangeQuery(1, i - 1);
    for (int b = 0; b <= M; ++b) {
      int x = extractFront(A[i], b);
      if (mq[x] < 1000000007) dp[i] = min(dp[i], (mq[x]) + off + M - b);
    }
    off += M - consecIntrsx[i];
    for (int b = 0; b <= M; ++b) {
      int x = extractRear(A[i - 1], b);
      mq[x] = min(mq[x], dp[i] - off);
    }
  }
  int ans = rangeQuery(1, N);
  ans = min(ans, dp[N]);
  for (int i = 1; i < N; ++i) {
    ans = min(ans, dp[i] + rangeQuery(i + 1, N));
  }
  cout << ans;
}
