n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
f = 0
for i in range(len(a)):
    if f == 1:
        break
    for j in range(len(b)):
        if a[i] == b[j]:
            print(a[i])
            f = 1
            break    
if f == 0:
    min_1 = min(a)
    min_2 = min(b)
    if min_1 > min_2:
        print(min_2, min_1, sep='')
    else:
        print(min_1, min_2, sep='')