# Search for Pretty Integers

n = raw_input().split(' ')

t1 = raw_input().split(' ')
t2 = raw_input().split(' ')

l = []

for i in range(int(n[0])):
    for j in range(int(n[1])):
        if t1[i] == t2[j]:
            l.append(int(t1[i]))
        a = ""
        a = t1[i] + t2[j]
        l.append(int(a))

print min(l)
   		 	     		 	    			   	 			