import itertools def main(): N = int(input()) A = [input() for i in range(N)] M = int(input()) B = [input() for i in range(M)] if tuple(sorted(A)) == tuple(sorted(B)): ans = -1 else: 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_ break print(ans) main()