n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
common = set(a) & set(b)
if len(common) > 0:
  print(sorted(list(common))[0])
elif min(a) < min(b):
  print(min(a) * 10 + min(b))
else:
  print(min(b)* 10 + min(a))