#include #include #include using namespace std; int n, m, cnt; string ans; vector s1, s2; int main() { // freopen("ring.in", "r", stdin); // freopen("ring.out", "w", stdout); scanf("%d", &n); s1.resize(n + 1); for (int i = 1; i <= n; ++i) { cin >> s1[i]; } scanf("%d", &m); s2.resize(m + 1); for (int i = 1; i <= m; ++i) { cin >> s2[i]; } do { do { string str1, str2; for (int i = 0; i < s1.size(); ++i) { str1 += s1[i]; } for (int i = 0; i < s2.size(); ++i) { str2 += s2[i]; } bool ok = false; for (int i = 0; i < str1.size(); ++i) { if (str1[i] != str2[i]) break; if (i == str1.size() - 1) { if (ans != str1 || ans == "") { ++cnt; ok = true; } } } if (cnt > 1) { puts("-1"); return 0; } if (ok) { ans = str1; } } while (next_permutation(s2.begin(), s2.end())); } while (next_permutation(s1.begin(), s1.end())); cout << ans << endl; return 0; }