n, m = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for i in range (len(a)):
    for i1 in range (len(b)):
        if a[i] == b[i]:
            print (a[i])
            exit(0)
else:
    a = min(a)
    b = min(b)
    print(min(a,b)*10+max(a,b))
