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

arr1 = [int(a) for a in input().split()]
arr2 = [int(a) for a in input().split()]

for element in arr1:
  if element in arr1 and element in arr2 and element < min1:
    min1 = element
  if element < minimum1:
    minimum1 = element

for element in arr2:
  if element in arr1 and element in arr2 and element < min2:
    min2 = element
  if element < minimum2:
    minimum2 = element
    
if min2 == min1:
  print(min1)
else:
  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)

  
  
