n,m = map(int, input().split())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
a1 = min(a)
b1 = min(b)
st= str()
if a1>b1:
	print(str(b1) + str(a1))
elif a1==b1:
	print(str(a1))
else:
	print(str(a1) + str(b1))
