s=list(map(int,input().split()))
k=list(map(int,input().split()))
h=list(map(int,input().split()))
k.sort()
t=0
h.sort()
if(len(k)>len(h)):
    for i in range(len(h)):
        if(h[i] in k):
            print(h[i])
            t=1
            break
else:
    for i in range(len(k)):
        if(k[i] in h):
            print(k[i])
            t=1
            break
if(t==0):
    if(k[0]>h[0]):
        print(h[0]*10+k[0])
    else:
        print(k[0]*10+h[0])
