n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for step in range(len(a)):
    for i in range(len(a)-step-1):
        if a[i+1]<a[i]:
            a[i],a[i+1]=a[i+1],a[i]
for step in range(len(b)):
    for i in range(len(b)-step-1):
        if b[i+1]<b[i]:
            b[i],b[i+1]=b[i+1],b[i]
i=0
k=0
while k==0 and i!=len(a):
    for j in range(len(b)):
        if a[i]==b[j]:
            k=a[i]
    i+=1
if k>0:
    print(k)
else:
    if a[0]<b[0]:
        print(a[0],end='')
        print(b[0])
    else:
        print(b[0],end='')
        print(a[0])