n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ea=set(a)
eb=set(b)
if ea & eb !=set():
      print(min(list(ea & eb)))
else:
      ma=min(a)
      mb=min(b)
      print(min(ma,mb)*10+max(ma,mb))

