from sys import stdin, stdout 

N,M = stdin.readline().split()
N = map(int,stdin.readline().strip().split())
M = map(int,stdin.readline().strip().split())
n = min(N)
m = min(M)

a = min(m,n)
b = max(m,n)
no = a*10+b

l = list(set(N).intersection(M))
if len(l)>0:
	l0 = min(l)
	stdout.write(str(l0)+'\n')
else:
	stdout.write(str(no)+'\n')



	
