IL = lambda: list(map(int, input().split()))
I = lambda: int(input())

n, m = IL()
a = set(IL())
b = set(IL())
un = a.intersection(b)
if len(un):
    print(min(un))
else:
    un = sorted([min(a), min(b)])
    print(un[0]*10 + un[1])