#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> words;
vector<int> wlen;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
words.resize(n);
wlen.resize(n);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
int cur = 0;
wlen[i] = int(s.size());
for (int j = 0; j < wlen[i]; j++) {
cur = 2 * cur + int(s[j] - '0');
}
words[i] = cur;
}
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
vector<vector<int> > dist(n);
for (int i = 0; i < n; i++) {
dist[i].assign(wlen[i]+1, -1);
dist[i][wlen[i]] = wlen[i];
pq.push(make_pair(wlen[i], i * 20 + wlen[i]));
}
while (!pq.empty()) {
int d = pq.top().first;
int cur = pq.top().second;
int i = cur / 20;
int r = cur % 20;
pq.pop();
if (r == 0) {
cout << d << '\n';
exit(0);
}
if (dist[i][r] < d) continue;
int suffix = words[i] & ((1 << r) - 1);
for (int j = 0; j < n; j++) {
if (i == j && r == wlen[j]) continue;
int newi = -1, newr = -1, extra = 0;
if (wlen[j] <= r) {
if ((suffix >> (r - wlen[j])) == words[j]) {
newi = i;
newr = r - wlen[j];
extra = 0;
}
} else {
if (suffix == (words[j] >> (wlen[j] - r))) {
newi = j;
newr = wlen[j] - r;
extra = newr;
}
}
if (newi == -1) continue;
int newd = d + extra;
if (dist[newi][newr] == -1 || dist[newi][newr] > newd) {
dist[newi][newr] = newd;
pq.push(make_pair(newd, newi * 20 + newr));
}
}
}
cout << 0 << '\n';
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbjsKdmVjdG9yPGludD4gd29yZHM7CnZlY3RvcjxpbnQ+IHdsZW47CgppbnQgbWFpbigpIHsKCWlvczo6c3luY193aXRoX3N0ZGlvKDApLCBjaW4udGllKDApOwoJY2luID4+IG47Cgl3b3Jkcy5yZXNpemUobik7Cgl3bGVuLnJlc2l6ZShuKTsKCWZvciAoaW50IGkgPSAw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