#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
template<typename T = int,
        typename E = int,
        typename F = function<T(T, E)>,
        typename Compare = function<T(T, T) >>
class Dijkstra {
public:
    Int N;
    T s_value;
    T init_value;
    F f;
    Compare cmp;

    vector<T> dist;
    vector<vector<pair<int, E>>>
            G; // first : index, second : E


    Dijkstra(Int N, T init_value = INF, T s_value = 0,
             F f = [](T l, E r) { return l + r; },
             Compare cmp = [](T l, T r) { return l > r; }
    ) : N(N), s_value(s_value), init_value(init_value), f(f), cmp(cmp) {
        dist.resize(N, init_value);
        G.resize(N);
    }

    void add_edge(int f, int t, E e) {
        G[f].push_back(make_pair(t, e));
    }

    void compute(int s) {
        using P = pair<T, int>;
        auto pq_cmp = [this](P l, P r) -> bool {
            return cmp(l.first, r.first);
        };
        priority_queue<P, vector<P>, decltype(pq_cmp)> que(pq_cmp);
        fill(dist.begin(), dist.end(), init_value);
        dist[s] = s_value;

        que.push(P(dist[s], s));

        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;

//            if (!cmp(dist[v], p.first) && (dist[v] != p.first)) continue;
            if (cmp(p.first, dist[v])) continue;

            for (int i = 0; i < G[v].size(); i++) {
                int to_idx = G[v][i].first;
                E to_e = G[v][i].second;

                if (cmp(dist[to_idx], f(dist[v], to_e)) && !(dist[to_idx] == init_value && dist[v] == init_value)) {
                    dist[to_idx] = f(dist[v], to_e);
                    que.push(P(dist[to_idx], to_idx));
                }
            }
        }
    }

    T get_dist(int v) {
        return dist[v];
    }


};

class Solve {
public:
    pair<int, string> cat(string s, string t) {
        pair<int, string> ret(-1, "");
        if (s.size() < t.size()) {
            if (s == t.substr(0, s.size())) {
                ret = {t.size() - s.size(), t.substr(s.size())};
            }
        } else {
            if (t == s.substr(0, t.size())) {
                ret = {0, s.substr(t.size())};
            }
        }

        return ret;
    }

    void solve() {
        Int n;
        cin >> n;
        vector<string> w(n);
        rep(i, 0, n) cin >> w[i];


        map<string, int> id;
        for (auto e : w) {
            while (e.size() > 0) {
                e = e.substr(1);
                id[e] = -1;
            }
        }

        {
            int cnt = 0;
            set<string> st;
            for (auto e : id) {
                st.insert(e.first);
            }
            for (auto e : st) {
                id[e] = cnt++;
            }
        }

//        for (auto e : id) {
//            cout << e.first << " " << e.second << endl;
//        }


        Int start = id.size();
        Int term = start + 1;
        Dijkstra<Int> dij(term + 1, INFl);

        for (auto p : id) {
            rep(i, 0, n) {
                // add edge joutai p.first + w[i]
                string s = p.first;
                string t = w[i];
                auto tapu = cat(s, t);
                if (tapu.first != -1) {
                    Int from = id[s];
                    Int to = id[tapu.second];
                    Int cost = tapu.first;
                    dij.add_edge(from, to, cost);
                }
            }
        }

        rep(i, 0, n) {
            rep(j, 0, n) {
                if (i == j) continue;

                string s = w[i];
                string t = w[j];
                auto tapu = cat(s, t);
                if (tapu.first != -1) {
                    Int from = start;
                    Int to = id[tapu.second];
                    Int cost = max(s.size(), t.size());
                    dij.add_edge(from, to, cost);
                }
            }

            dij.add_edge(id[w[i]], term, 0);
        }


        dij.compute(start);
        Int ans = dij.get_dist(term);
        if (ans == INFl) {
            ans = 0;
        }
        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    Solve().solve();


    return 0;
}



Measured memory_bytes: 4160