#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
const int INF = 2e9;
void doh(int &x, int i, int len) {
  if (x == -1) return;
  if (x & (1 << (len - 1 - i))) {
    x ^= (1 << (len - 1 - i));
  }
}
void doan(int &x) { x = (x >> 1); }
int compable(int f, int s, int len) {
  if (f == -1) return len;
  for (int i = 0; i < (len); i++) {
    if (f == s) return i;
    doh(f, i, len);
    doan(s);
  }
  return len;
}
int dp[(1 << 20) + 10][21];
int upd[(1 << 20) + 10][21];
int last, all = 0;
void apply(int x, int y) {
  dp[x][y] += (all - upd[x][y]);
  upd[x][y] = all;
}
int main() {
  memset(upd, 0, sizeof upd);
  int n;
  cin >> n;
  char buf[30];
  gets(buf);
  for (int i = 0; i < ((1 << 20) + 10); i++) {
    for (int j = 0; j < (21); j++) {
      dp[i][j] = INF;
    }
  }
  int len;
  for (int i = 0; i < (n); i++) {
    gets(buf);
    len = strlen(buf);
    int num = 0;
    for (int j = 0; j < (len); j++) {
      if (buf[len - 1 - j] == '1') {
        num ^= (1 << j);
      }
    }
    if (!i) {
      dp[0][len] = len;
      last = num;
      continue;
    }
    int add = compable(last, num, len);
    all += add;
    int temp = num;
    vector<int> gogo;
    for (int j = 0; j < (len + 1); j++) {
      apply(temp, j);
      int val = dp[temp][j] - add;
      if (val < INF) {
        gogo.push_back(val + j);
      }
      doan(temp);
    }
    for (int j = 0; j < ((int)gogo.size()); j++) {
      int val = gogo[j];
      int temp2 = last;
      for (int k = 0; k < (len + 1); k++) {
        apply(temp2, k);
        if (dp[temp2][k] > val) {
          dp[temp2][k] = val;
        }
        doh(temp2, k, len);
      }
    }
    last = num;
  }
  int val = INF;
  for (int i = 0; i < ((1 << 20) + 10); i++)
    for (int j = 0; j < (21); j++) {
      apply(i, j);
      val = min(val, dp[i][j]);
    }
  cout << val;
}
