n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
o = []
for i in range(n):
    for t in range(m):
        if a[i] == b[t]:
            o.append(a[i])
if len(o) > 0:
    print(min(o))
else:
    z = min(a)
    x = min(b)
    if z >= x:
        print(x * 10 + z)
    else:
        print(z * 10 + x)