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

p = list(n & m)

if len(p) > 0 :
   print(min(p))
else :
   ans = min(min(n) * 10 + min(m), min(m) * 10 + min(n))
   print(ans)