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

arr1 = input().split()
arr2 = input().split()

for element in arr1:
  element = int(element)
  if element < minimum1:
    minimum1 = element

for element in arr2:
  element = int(element)
  if element < minimum2:
    minimum2 = element

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


print(ans)

  
  
