t=input()
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
def func():
  min_same=10000
  for i in x:
    for j in y:
      if (i==j) and i<min_same:
        min_same=i
  if min_same!=10000:
    return min_same
  min1=min(x)
  min2=min(y)
  if (min1>min2):
    return str(min2)+str(min1)
  else:
    return str(min1)+str(min2)
print(func())    