n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = set(a)
k1 = set(b)
if len(k & k1)>0:
  print(min(k & k1))
else:
  print(min(min(a), min(b))*10 + max(min(a), min(b)))