from collections import deque
n, m = list(map(int, input().split()))
a = list([i for i in map(int, input().split())])
b = list([i for i in map(int, input().split())])

am = min(a)
bm = min(b)
c = a+ b
t = True
c.sort()
for i in c:
    if c.count(i) > 1:
        print(i)
        t = False
        break

if t:
    print(str(min(am, bm)) + str(max(am, bm)))
