On an IT lesson Valera studied data compression. The teacher told about a new method, which we shall now describe to you.

Let {a1, a2, ..., an} be the given sequence of lines needed to be compressed. Here and below we shall assume that all lines are of the same length and consist only of the digits 0 and 1. Let's define the compression function:

  * f(empty sequence) = empty string 
  * f(s) = s. 
  * f(s1, s2) =  the smallest in length string, which has one of the prefixes equal to s1 and one of the suffixes equal to s2. For example, f(001, 011) = 0011, f(111, 011) = 111011. 
  * f(a1, a2, ..., an) = f(f(a1, a2, an - 1), an). For example, f(000, 000, 111) = f(f(000, 000), 111) = f(000, 111) = 000111. 



Valera faces a real challenge: he should divide the given sequence {a1, a2, ..., an} into two subsequences {b1, b2, ..., bk} and {c1, c2, ..., cm}, m + k = n, so that the value of S = |f(b1, b2, ..., bk)| + |f(c1, c2, ..., cm)| took the minimum possible value. Here |p| denotes the length of the string p.

Note that it is not allowed to change the relative order of lines in the subsequences. It is allowed to make one of the subsequences empty. Each string from the initial sequence should belong to exactly one subsequence. Elements of subsequences b and c don't have to be consecutive in the original sequence a, i. e. elements of b and c can alternate in a (see samples 2 and 3).

Help Valera to find the minimum possible value of S.

Input

The first line of input data contains an integer n — the number of strings (1 ≤ n ≤ 2·105). Then on n lines follow elements of the sequence — strings whose lengths are from 1 to 20 characters, consisting only of digits 0 and 1. The i + 1-th input line contains the i-th element of the sequence. Elements of the sequence are separated only by a newline. It is guaranteed that all lines have the same length.

Output

Print a single number — the minimum possible value of S.

Examples

Input

3
01
10
01


Output

4


Input

4
000
111
110
001


Output

8


Input

5
10101
01010
11111
01000
10010


Output

17

Note

Detailed answers to the tests:

  * The best option is to make one of the subsequences empty, and the second one equal to the whole given sequence. |f(01, 10, 01)| = |f(f(01, 10), 01)| = |f(010, 01)| = |0101| = 4. 
  * The best option is: b = {000, 001}, c = {111, 110}. S = |f(000, 001)| + |f(111, 110)| = |0001| + |1110| = 8. 
  * The best option is: b = {10101, 01010, 01000}, c = {11111, 10010}. S = |10101000| + |111110010| = 17. 
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n, dps[MAXN], dpd[MAXN], ps[MAXN];
int mxs[(1 << 20)][21];
bool se[(1 << 20)][21];
string w[MAXN];
void setmxs(int ii, int sz, int val) {
  if (!se[ii][sz])
    mxs[ii][sz] = val, se[ii][sz] = 1;
  else
    mxs[ii][sz] = min(mxs[ii][sz], val);
}
int getmxs(int ii, int sz) {
  if (se[ii][sz]) return mxs[ii][sz];
  return -1e9;
}
int getdif(string &a, string &b) {
  for (int s = 0; s < a.size(); s++) {
    int ts = s;
    bool ok = 1;
    for (int j = 0; j < b.size() && ts < a.size(); j++, ts++)
      if (a[ts] != b[j]) {
        ok = false;
        break;
      }
    if (ok) return s;
  }
  return a.size();
}
void addtomx(int ind, int val) {
  ind--;
  setmxs(0, 0, val);
  for (int i = 0; i < w[ind].size(); i++) {
    int res = 0, sz = 0;
    for (int j = i; j < w[ind].size(); j++) {
      sz++, res *= 2;
      if (w[ind][j] == '1') res += 1;
    }
    setmxs(res, sz, val);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
    if (i > 0) ps[i] = ps[i - 1] + getdif(w[i - 1], w[i]);
  }
  dpd[0] = w[0].size();
  dpd[1] = w[1].size() * 2;
  for (int i = 2; i < n; i++) {
    dpd[i] = dpd[i - 1] + getdif(w[i - 2], w[i]);
    dpd[i] = min(dpd[i], ps[i - 1] + (int)w[0].size() + (int)w[i].size());
    if (i > 2) {
      addtomx(i - 2, dpd[i - 2] - ps[i - 2]);
      for (int j = -1; j < (int)w[i].size(); j++) {
        int sz = 0, res = 0;
        for (int k = 0; k <= j; k++) {
          sz++, res *= 2;
          if (w[i][k] == '1') res += 1;
        }
        int t = getmxs(res, sz);
        if (t != -1e9)
          dpd[i] = min(dpd[i], t + ((int)w[i].size() - j - 1) -
                                   getdif(w[i - 1], w[i]) + ps[i]);
      }
    }
  }
  dps[0] = w[0].size();
  for (int i = 1; i < n; i++)
    dps[i] = min(dpd[i - 1], dps[i - 1]) + getdif(w[i - 1], w[i]);
  cout << min(dpd[n - 1], dps[n - 1]);
}
