listsLength = list(map(int, input().split()))
firstList = list(map(int, input().split()))
secondList = list(map(int, input().split()))

minFirstList = min(firstList)
minSecondList = min(secondList)

repitedNum = []

for n in firstList:
  if(n in secondList):
    repitedNum.append(n)

if(len(repitedNum)):
  print(min(repitedNum))
elif(minFirstList in secondList):
  print(minFirstList)
elif(minSecondList in firstList):
  print(minSecondList)
else:
  digitA = min(minFirstList, minSecondList)
  digitB = max(minFirstList, minSecondList)
  print(str(digitA) + str(digitB))