#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
const double error = 1e-7;
const double PI = acos(-1);
mt19937 rng(
    (unsigned int)chrono::system_clock::now().time_since_epoch().count());
inline long long int MOD(long long int x, long long int m = mod) {
  long long int y = x % m;
  return (y >= 0) ? y : y + m;
}
const int inf = 1e9;
const unsigned long long int infl = 1e18 + 1;
const int nmax = 1e5 + 5;
vector<string> input;
vector<int> arr;
int emptyprev;
vector<vector<int> > DS;
int lazy = 0;
void build(int len) {
  emptyprev = 0;
  DS.resize(len + 1);
  for (int s = 0; s <= len; s++) DS[s].resize((1LL << (s)), inf);
  DS[0][0] = 0;
}
inline int func(int i, int j, int len) {
  if (i < 0) return len;
  int ret = 0;
  for (int k = 1; k <= len; k++) {
    if ((arr[i] & ((1LL << (k)) - 1)) == (arr[j] >> (len - k))) ret = k;
  }
  return len - ret;
}
void update(int i, int len) {
  int tmp = func(i - 1, i, len);
  if (i != 0) {
    int cand = inf;
    for (int s = len; s >= 0; s--) {
      int suf = arr[i] >> (len - s);
      cand = min(DS[s][suf] + lazy + len - s, cand);
    }
    cand = min(cand, emptyprev + lazy + len);
    cand -= lazy + tmp;
    DS[len][arr[i - 1]] = min(DS[len][arr[i]], cand);
    for (int s = len - 1; s >= 0; s--) {
      int suf = arr[i - 1] & ((1LL << (s)) - 1);
      DS[s][suf] = min(DS[s + 1][suf | (1LL << (s))], DS[s + 1][suf]);
    }
    DS[0][0] = min(DS[0][0], emptyprev);
  }
  lazy += tmp;
}
void dbg(int s) {
  cout << "empty : " << emptyprev + lazy << "\n";
  for (int i = 0; i < (1LL << (s)); i++)
    if (DS[s][i] < inf)
      cout << bitset<5>(i) << " : " << DS[s][i] + lazy << "\n";
}
int main() {
  int n;
  cin >> n;
  input.resize(n);
  arr.resize(n);
  int len;
  for (int i = 0; i < n; i++) {
    cin >> input[i];
    len = input[i].size();
    for (int j = 0, k = len - 1; j < len; j++, k--)
      if (input[i][j] == '1') arr[i] |= (1LL << (k));
  }
  build(len);
  for (int i = 0; i < n; i++) {
    update(i, len);
  }
  int ans = DS[0][0] + lazy;
  cout << ans;
}
