aux = input()

ans = 10000
a = list(map(int, input().split()))
b = list(map(int, input().split()))

for i in a:
	if(i in b):
		ans = min(ans, i)
if(ans != 10000):
	print(ans)
else:
	a.sort()
	b.sort()
	ans = []
	ans.append(a[0])
	ans.append(b[0])
	ans.sort()
	if(ans[0]==ans[1]):
		print(ans[0])
	else:
		print(ans[0], ans[1], sep='')	
	


