n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = []
v = False
for el in a:
    if el in b:
        c.append(el)
        v = True
if v == False:
    print(min(min(a), min(b)), end = '')
    print(max(min(a), min(b)), end = '')
else:
    c.sort()
    print(c[0])