input()
a=set([int(x) for x in input().split()])
b=set([int(x) for x in input().split()])
c = a&b
if len(c)>0:
    print(sorted(list(c))[0])
else:
    a = sorted(list(a))[0]
    b = sorted(list(b))[0]
    if a>b:
        print(b,a,sep="")
    else:
        print(a,b,sep="")