#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

struct edge{
    int to,dist;
};

struct state{
    int node,dist;
    bool operator<(const state& r)const{
        return dist>r.dist;
    }
};

int main(){
    int N;
    cin >> N;
    vec<string> W(N);
    map<string,int> m;
    int id = 1;
    for(int i=0;i<N;i++){
        cin >> W[i];
        int n = W[i].size();
        for(int j=0;j<n;j++){
            string S = W[i].substr(n-j-1,j+1);
            if(!m.count(S)) m[S] = id++;
        }
    }
    const int s = 0,t = id;
    vvec<edge> g(id+1);
    m[""] = t;
    for(auto& x:m){
        string S = x.first;
        if(S=="") continue;
        int n = S.size();
        for(int i=0;i<N;i++){
            if(W[i].size()<n){
                if(S.substr(0,W[i].size())==W[i]){
                    string T = S.substr(W[i].size(),n-W[i].size());
                    g[x.second].push_back({m[T],0});
                }
            }
            else if(S==W[i].substr(0,n)){
                string T = W[i].substr(n,W[i].size()-n);
                g[x.second].push_back({m[T],(int) T.size()});
            }
        }
    }
    int inf = 1e9;
    vec<int> dp(id+1,inf);
    dp[s] = 0;
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++){
        string S = W[i],T = W[j];
        if(S.size()>T.size()) swap(S,T);
        if(S!=T.substr(0,S.size())) continue;
        string R = T.substr(S.size(),T.size()-S.size());
        g[s].push_back({m[R],(int) T.size()});
    }
    priority_queue<state> Q;
    Q.push({s,0});
    while(!Q.empty()){
        state now = Q.top(); Q.pop();
        if(dp[now.node]<now.dist) continue;
        for(auto& e:g[now.node]){
            int c = now.dist+e.dist;
            if(dp[e.to]>c){
                dp[e.to] = c;
                Q.push({e.to,c});
            }
        }
    }
    cout << (dp[t]!=inf? dp[t]:0) << endl;
}
