#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
template <typename T>
bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int N;
string w[1005];
int num = 0;
map<string, int> inv;
map<int, string> mapping;
string now;
vector<l_l> paths[140000];
ll dist[140000];
bool searched[140000];
int start = 1;
int goal;
void initialize() {
    num++;
    inv[now] = num;
    mapping[num] = now;
    //cerr << num << " " << now << endl;
    if(now.size() == 16) {
        return;
    }
    now.push_back('0');
    initialize();
    now.pop_back();
    now.push_back('1');
    initialize();
    now.pop_back();
}

void EDGEMAKE(string S) {
    if(now.size() + S.size() > 16) return;
    int from = inv[S + now];
    int to = inv[now];
    if(!now.empty()) paths[from].push_back({to, S.size()});
    now.push_back('0');
    EDGEMAKE(S);
    now.pop_back();
    now.push_back('1');
    EDGEMAKE(S);
    now.pop_back();
}

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    initialize();
    cin >> N;
    goal = num + 1;
    for(int i = start; i <= goal; i++) {
        dist[i] = 1e18;
    }
    priority_queue<l_l, vector<l_l>, greater<l_l>> que;
    dist[start] = 0;
    que.push({0, start});
    for(int i = 1; i <= N; i++) {
        cin >> w[i];
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j < w[i].size(); j++) {
            int from = inv[w[i].substr(0, j)];
            int to = inv[w[i].substr(j, (int)w[i].size())];
            paths[from].push_back({to, j});
        }
        paths[inv[w[i]]].push_back({goal, w[i].size()});
        EDGEMAKE(w[i]);
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            if(w[i].size() >= w[j].size()) continue;
            if(w[j].substr(0, (int)w[i].size()) != w[i]) continue;
            paths[start].push_back({inv[w[j].substr(w[i].size(), 16)], w[i].size()});
            //cerr << w[i] << " " << w[j] << endl;
        }
    }
    for(int i = 0; i <= num; i++) {
        if (paths[i].empty()) continue;
        //cerr << "------" << mapping[i] << "-----" << endl;
        for (auto val : paths[i]) {
            //cerr << mapping[val.first] << " " << val.second << endl;
        }
    }
    while(!que.empty()) {
        ll from = que.top().second;
        ll nowcost = que.top().first;
        que.pop();
        if(searched[from]) continue;
        searched[from] = true;
        if(from == goal) {
            cout << dist[from] << endl;
            return 0;
        }
        //cerr << "FROM:" << mapping[from] << " " << dist[from] << endl;
        for(auto val : paths[from]) {
            ll to = val.first;
            ll newcost = nowcost + val.second;
            /*
            if(to == goal) {
                //cerr << mapping[from] << "->" << mapping[to] << " " << dist[from] << endl;
                if (nowcost == 0) continue;
            }
             */
            //cerr << mapping[from] << "->" << mapping[to] << " " << dist[from] << endl;
            if(chmin(dist[to], newcost)) {
                que.push({newcost, to});
            }
        }
    }
    cout << 0 << endl;
    return 0;
}
