n, m = map(int, input().split())
ns = list(map(int, input().split()))
fs = list(map(int, input().split()))
ls = list(set(ns)&set(fs))
if len(ls):
  print(min(ls))
else:
  print(min(str(min(ns))+str(min(fs)),str(min(fs))+str(min(ns))))