#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
 
template <typename T>
void cetak(T t){cout << t << ')' << endl;}
template <typename T, typename... V>
void cetak(T t, V... v) {cout << t; if (sizeof...(v)) cerr << ", "; cetak(v...);}
 
#define debug(x...) cout<< '(' << #x << ") = ("; cetak(x) 
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())

const int MOD = 1e9 + 7;
const int mx = 1e5 + 10;

int n;
string ss[mx];
vector<pair<int, int>> g[18][(1 << 16) + 10];
int isi[18][(1 << 16) + 10];
int dist[18][(1 << 16) + 10];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;
    for(int i = 0; i < n; i++) cin >> ss[i];
    for(int i = 0; i < n; i++){
        int ret = 0;
        for(int j = 0; j < sz(ss[i]); j++){
            ret *= 2;
            ret += ss[i][j] - '0';
            int sisa = 0;
            for(int k = j + 1; k < sz(ss[i]); k++){
                sisa *= 2;
                sisa += ss[i][k] - '0';
            }
            // debug(i, j + 1, ret, sz(ss[i]) - j - 1, sisa);
            g[j + 1][ret].pb({sz(ss[i]) - j - 1, sisa});
        }
        isi[sz(ss[i])][ret] = 1;
    }
    priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;
    reset(dist, -1);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(sz(ss[i]) <= sz(ss[j])) continue;
            int ya = 1;
            for(int k = 0; k < sz(ss[j]); k++){
                if(ss[i][k] != ss[j][k])
                    ya = 0;
            }
            if(!ya) continue;
            ya = 1;
            int ret = 0;
            for(int k = sz(ss[j]); k < sz(ss[i]); k++){
                ret *= 2;
                ret += ss[i][k] - '0';
            }
            // debug(i, j, ret);
            pq.push({sz(ss[i]), {sz(ss[i]) - sz(ss[j]), ret}});
            dist[sz(ss[i]) - sz(ss[j])][ret] = sz(ss[i]);
        }
    }
    while(!pq.empty()){
        auto now = pq.top().s;
        auto dis = pq.top().f;
        pq.pop();
        if(dis > dist[now.f][now.s]) continue;
        int jadi = 0;
        for(int i = 1; i <= now.f; i++){
            jadi *= 2;
            if(now.s & (1 << (now.f - i))) jadi += 1;
            if(isi[i][jadi]){
                int sisa = now.s - (jadi << (now.f - i));
                if(dist[now.f - i][sisa] == -1 || dist[now.f - i][sisa] > dis){
                    dist[now.f - i][sisa] = dis;
                    pq.push({dis, {now.f - i, sisa}});
                }
            }
        }
        for(auto i : g[now.f][now.s]){
            // debug(i.f)
            int nex = dis + i.f;
            if(dist[i.f][i.s] == -1 || dist[i.f][i.s] > nex){
                dist[i.f][i.s] = nex;
                pq.push({nex, i});
            }
        }
    }
    if(dist[0][0] == -1) dist[0][0] += 1;
    cout << dist[0][0] << endl;
}  
