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