n,m=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
min1=10
min2=10
min3=10
for i in range (n):
    a[i]=int(a[i])
for i in range (m):
    b[i]=int(b[i])
for i in range (n):
    if (a[i]<min1):
        min1=a[i]
for i in range (m):
    if (b[i]<min2):
         min2=b[i]
for i in range(n):
    for j in range(m):
        if a[i]==b[j]:
            if a[i]<min3:
                min3=a[i];
if (min3!=10):
    print(min3)
    exit()
else:
    min3=(str(min(min1,min2))+(str(max(min1,min2))))
    print(min3)
