a,b = map(int,input().split())
m = sorted(list(map(int,input().split())))
n = sorted(list(map(int,input().split())))
z =0
for i in m:
	if i in n:
		z =1
		print(i)
		break
if z !=1:
	print(str(min(m[0],n[0]))+str(max(m[0],n[0])))



