x,y = map(int, input().split())
first = list(map(int, input().split()))
second = list(map(int, input().split()))
mf = min(first)
ms = min(second)

if ms > mf:
	resp = str(mf) + str(ms)
elif ms == mf:
	resp = ms
else:
	resp = str(ms) + str(mf)

resp = int(resp)
print(resp)
