#include using namespace std; #define pb emplace_back #define mp make_pair using ll = long long; using pii = pair; constexpr int mod = 998244353; constexpr int inf = 0x3f3f3f3f; constexpr int N = 2e5 + 10; string ok(int n, vector> &cnt, vector &num){ for(int i=0; i 2) continue; for(int k=0; k<26; ++k){ if(cnt[i][k] + 1 == cnt[j][k]){ if(pos >> k & 1){ pos ^= (1 << k); break; } } } } if(!pos) continue; string ret = ""; ++cnt[i][__builtin_ctz(pos)]; for(int j=0; j<26; ++j){ while(cnt[i][j]--) ret += (char)(j + 'a'); } return ret; } return "-1"; } void _main(){ int n; string s; cin >> n; vector> cnt(n, vector(26, 0)); vector num(n, 0); for(int i=0; i> s; num[i] = s.length(); for(char c : s) ++cnt[i][c - 'a']; } cout << ok(n, cnt, num) << '\n'; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); _main(); return 0; }