#a = int(input())
n, m = map(int, input().split())
an = list(map(int, input().split()))
am = list(map(int, input().split()))
an.sort()
an[:]
am.sort()
am[:]
i = 0
j = 0
flag = True
while i < n and j < m:
    if an[i] > am[j]:
        j += 1
    elif an[i] < am[j]:
        i += 1
    else:
        flag = False
        print(an[i])
        break
if flag:
    l = min(an[0], am[0])
    r = max(an[0], am[0])
    if l == r:
        print(l)
    else:
        print(10 * l + r)