import sys
m,n = [int(i) for i in input().split()]
a_s = set([int(i) for i in input().split()])
b_s = set([int(i) for i in input().split()])
per = (b_s & a_s)
if per:
    print(min(per))
    sys.exit(0)
min_a = min(a_s)
min_b = min(b_s)
if min_b > min_a:
    print(str(min_a) + str(min_b))
elif min_a > min_b:
    print(str(min_b) + str(min_a))
elif min_b == min_a:
    print(str(min_b)*2)