entry = input()

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

found = False
for i in range(10):
  if(i in l1 and i in l2):
    print(i)
    found = True
    break

if(not found):
  min_l1 = min(l1)
  min_l2 = min(l2)
  if(min_l1 < min_l2):
    print("%d%d"%(min_l1,min_l2))
  else:
    print("%d%d"%(min_l2,min_l1))