n,m = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

m1 = min(a)
m2 = min(b)

if m1 != m2:
  if m1 > m2:
    print(str(m2)+str(m1))
  else:
    print(str(m1)+str(m2))
else:
  print(m1)
