n,m = map(int,input().split())
mat = set(map(int, input().split()))
sat = set(map(int, input().split()))
inter = mat.intersection(sat)
if len(inter)!=0:
    print(min(inter))
else:
    mm = min(mat)
    ms = min(sat)
    print(str(mm)+str(ms) if mm<ms else str(ms)+str(mm))
