from sys import stdin as fin
# fin = open("tc172a.in", "r")

# n = int(fin.readline())
n, m = map(int, fin.readline().split())
arr1 = list(map(int, fin.readline().split()))
arr2 = list(map(int, fin.readline().split()))
# print(n, m)
# print(arr1, arr2)
# s = fin.readline().rstrip()
arr1.sort()
arr2.sort()
a, b = arr1[0], arr2[0]
flag = False
for x in arr1:
    for y in arr2:
        if x == y:
            flag = True
            break
    if flag:
        print(x)
        break
else:
    if a > b:
        a, b = b, a
    print(a, b, sep='')
