n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

f = True
for i in range(0, 11):
    if i in a and i in b and f:
        print(i)
        f = False
if f:
    if min(a) == min(b):
        print(min(a))
    else:
        print(min(min(a), min(b)), max(min(a), min(b)), sep='')
