# cook your dish here
n,m=input().split()
n,m=int(n),int(m)
a=list(map(int,input().split()))
b=list(map(int,input().split()))
m1=min(a)
m2=min(b)
if(m1==m2):
    print(m1)
else:
    x=100
    y=100
    for i in range(n):
        for j in range(m):
            if(b[j]==a[i]):
                x=a[i]
            if(x<y):
                y=x
    if(y==100):
        print(min(m1,m2)*10+max(m1,m2))
    else:
        print(y)