import itertools def main(): N = int(input()) A = [input() for i in range(N)] M = int(input()) B = [input() for i in range(M)] cnt = 0 for a in itertools.permutations(A): a_ = ''.join(a) for b in itertools.permutations(B): b_ = ''.join(b) if a_ == b_: ans = b_ cnt += 1 if cnt > 1: break if cnt > 1: print(-1) else: print(ans) main()