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()]
c = float('+inf')
for i in range(len(a)):
    for j in range(len(b)):
        if a[i] == b[j]:
            if a[i] < c:
                c = a[i]  
if c is not float:
    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='')
else:
    print(c)