n, m = [int(s) for s in input().split()]
a = {int(s) for s in input().split()}
b = {int(s) for s in input().split()}
c = a & b
if len(c) > 0:
    print(min(c))
else:
    print(min(a), end = '')
    print((min(b)))
