n, m = [int(i) for i in input().split()]

f = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]

fm = min(f)
sm = min(s)

if fm == sm: print(fm)
elif sm in f: print(sm)
elif fm in s: print(fm)
else: print(min(fm, sm)*10 + max(fm, sm))
