#include #include #include #include using namespace std ; /*ifstream cin ("input") ; ofstream cout ("output") ;*/ map H ; int solve (string s, int ind, vector &words) { // cout << s << '\n' ; if (s == "") { H [s] = 1 ; return 1 ; } if (H.find (s) != H.end()) { return H [s] ; } int best = 0 ; for (int j = 0 ; j <(int)words.size() ; ++ j) { if (j == ind) continue ; int i = 0 ; while (i < (int)s.size() and i < (int)words[j].size() and s [i] == words[j][i]) { ++ i ; } int lim = s.size(); string suf = "" ; while (i < lim) { suf += s [i] ; ++ i ; } if (suf.size() == s.size()) continue ; // cout << "sufixul este " << suf << '\n' ; best = max(best, solve (suf, ind, words)) ; } if (best == 0) return 0 ; H [s] = 1 ; return 1 ; } int main(int argc, char const *argv[]) { int n ; cin >> n ; vector v (n) ; for (int i = 0 ; i < n ; ++ i) { cin >> v [i] ; } int best = 0 ; string str = "" ; for (int i = 0 ; i < (int)v.size() ; ++ i) { if (solve (v[i], i, v)) { if (best < v [i].size()) { best = v [i].size() ; str = v [i] ; } } // cout << "=======================\n" ; } if (best == 0) cout << -1 ; else cout << str ; return 0; }