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): for b in itertools.permutations(B): a_ = ''.join(a) b_ = ''.join(b) if a_ == b_: ans = a_ cnt += 1 if cnt > 1: print(-1) else: print(ans) main()