n, m = map(int, input().split())
mas = list(map(int, input().split()))
gas = list(map(int, input().split()))
mas.sort()
gas.sort()
for a in range(n):
    for b in range(m):
        if mas[a] == gas[b]:
            print(mas[a])
            exit(0)
q = str(min(mas[0], gas[0])) + str(max(mas[0], gas[0]))
if q[0] == q[1]:
    print(q[0])
else:
    print(q)