# import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("out.out",'w')	
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=min(a)
y=min(b)
s=100
for i in range(n):
	if a[i] in b:
		s=min(s,a[i])
if s==100:
	s=min(x,y)*10+max(x,y)

print(s)	