i, j = map(int, input().split())
a=[int(n) for n in input().split()]
b=[int(m) for m in input().split()]
minn = 100
for nm in a:
  if min(a) == min(b):
    minn = min(a)
    break
  for mm in b:
    if nm*10+mm < minn:
      minn = nm*10+mm
    if mm*10+nm <minn:
      minn = mm*10+nm
print(minn)
