n, m = map(int, input().split())
s1 = [int(i) for i in input().split()]
s2 = [int(i) for i in input().split()]
c1 = s1[0] #инимальная цифра в списке 1
c2 = s2[0] #мин цифра в 2
A = []
for i in range(len(s2)):
    if s2[i] in s1:
        A.append(s2[i])
if A == []:
    for i in range(len(s1)):
        if s1[i] < c1:
            c1 = s1[i]

    for i in range(len(s2)):
        if s2[i] < c2:
            c2 = s2[i]

    if c1 > c2 or c1 < c2:
        p = [str(min(c1, c2)), str(max(c1, c2))]
        print(''.join(p))

else:
    p = 9
    for i in range(len(A)):
        if A[i] < p:
            p = A[i]
    print(p)
