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

a = list(map(int, input().split()))
b = list(map(int, input().split()))
both = []

for i in range(0, len(b)):

  if (b[i] in a):

    both.append(b[i])


min_a = min(a)
min_b = min(b)
min_both = 100

if (len(both) > 0):

  min_both = min(both)

min_res = min_a * 10 + min_b

if (min_res > min_both and min_b*10+min_a > min_both and (n > 1 or m > 1)):

  min_res = min_both

elif (min_a > min_b):

  min_res = min_b * 10 + min_a

elif (min_a == min_b):

  min_res = min_a


print(min_res)