input()
a = input()
b = input()

c = a.split(" ")
d = b.split(" ")

Number1 = []
Number2 = []

for numb in c:
    if numb != " ":
        Number1.append(int(numb))

for numb in d:
    if numb != " ":
        Number2.append(int(numb))

a.format()
b.format()

a = ""
b = ""

Number1.sort()
Number2.sort()

# Number1.index(Number2[0])
# Number2.index(Number1[0])

for numb in Number1:
    a += str(numb)
for numb in Number2:
    b += str(numb)


if (a.find(str(Number2[0])) != -1) or (b.find(str(Number1[0])) != -1):
    print(str(Number2[0]))
else:
    if Number1[0] > Number2[0]:
        print(str(Number2[0]) + str(Number1[0]))
    elif Number2[0] == Number1[0]:
        print(str(Number2[0]))
    else:
        print(str(Number1[0]) + str(Number2[0]))
