n,m=tuple([int(i) for i in input().split()])
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
x=min(a)
y=min(b)
fl=True

for i in a:
    if i in b:
        res=i
        fl=False
if fl:
    if (x>y):
        x,y=y,x
        res=x*10+y
    elif x<y:
        res=x*10+y

print(res)
