def intersection(lst1, lst2):
   lst3 = [value for value in lst1 if value in lst2]
   return lst3

a,b=map(int, input().split())

l1=list(map(int, input().split()))
l2=list(map(int, input().split()))
l3=intersection(l1,l2)

if len(l3)>0:
   print(min(l3))

else:
   x=min(l1)
   y=min(l2)
   if x>y:
      print(str(y)+str(x))
   else:
      print(str(x) + str(y))
