n, m = input().split(" ")
n = int(n)
m = int(m)

a = [int(c) for c in input().split(" ")]
b = [int(c) for c in input().split(" ")]

a.sort()
b.sort()

menor = 100000000000000

for i in a:
  for j in b:
    jun = int(str(i) + str(j))
    jun2 = int(str(j) + str(i))
    if i == j and i < menor:
      menor = i
    if jun < menor:
      menor = jun
    if jun2 < menor:
      menor = jun2

print(menor)