#include #include #include #include #include #include #include using namespace std; struct comp { bool operator()(string s, string t) { return s.size() < t.size(); } } mycomp; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector s; for (int i = 0; i < n; i++) { string st; cin >> st; s.push_back(st); } sort(s.begin(), s.end(), mycomp); bool found=false; for (int i = n-1; i >=0; i--) { int j=0; while (j < s[i].size()) { bool ok = false; for (int k = n-1; k >=0; k--) { if(s[k].size()<=s[i].size()-j && k != i) if ( s[i].compare(j,s[k].size(),s[k])==0) { j += s[k].size() ; ok = true; break; } } if (!ok) { break; } } if (j == s[i].size()) { found = true; cout << s[i]; break; } } if (!found) { cout << -1; } return 0; }