input()
a = set(map(int,input().split()))
b = set(map(int,input().split()))
x = y = float('inf')
both = None
for i in range(9,0,-1):
    if i in a:
        x = i
    if i in b:
        y = i
    if i in a and i in b:
        both = i
if both:
    print(both)
else:
    print(min(x*10+y,y*10+x))
