s=input()
n=int(s[0])
m=int(s[2])
q=input()
w=input()
a=[]
b=[]
c=10
d=10
e=10
for i in range(0,n):
    a.append(int(q[2*i]))
    if a[i]<c:
        c=a[i]
for k in range(0,m):
    b.append(int(w[2*k]))
    if b[k]<d:
        d=b[k]
    for h in range(0,n):
        if(a[h]==b[k]and a[h]<e):
            e=a[h]
if(e!=10):
    print(e)
else:
    if (c<d):
        print(c*10+d)
    else:
        print(d*10+c)
