#include using namespace std; #define int long long signed main(){ int n; cin >> n; vector a(n); for(int i = 0; i < n; i++)cin >> a[i]; int m; cin >> m; vector b(m); for(int i = 0; i < m; i++)cin >> b[i]; vector tmp(n), tmp1(m); for(int i = 0; i < n; i++)tmp[i] = i; for(int i = 0; i < m; i++)tmp1[i] = i; string s, s1; vector ans; do{ s = ""; for(int i = 0; i < n; i++)s += a[tmp[i]]; do{ s1 = ""; for(int j = 0; j < m; j++)s1 += b[tmp1[j]]; if(s == s1)ans.push_back(s); }while(next_permutation(tmp1.begin(), tmp1.end())); }while(next_permutation(tmp.begin(), tmp.end())); if(ans.size() == 1)cout << ans[0] << endl; else cout << -1 << endl; }