n, m = [int(a) for a in input().split()]
minimum1 = 10
minimum2 = 10
ans =  ''

for element in input().split():
  element = int(element)
  if element < minimum1:
    minimum1 = element

for element in input().split():
  element = int(element)
  if element < minimum2:
    minimum2 = element

ans += str(minimum1)
if int(ans) != minimum2:
  ans += str(minimum2)

print(ans)