n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort()
x = 101
for i in range(n):
	if a[i] in b:
		x = a[i]
		break
print(min(x,min((a[0]*10+b[0]),(b[0]*10+a[0]))))
