n, m = input().split()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dup = []
a.sort()
b.sort()
c = a[0]
d = b[0]

for i in a:
    if(i in b):
        dup.append(i)
        break

##print(dup)

if(len(dup) > 0):
    print(min(dup))
else:
    print(str(min(c, d))+str(max(c, d)))

		 							  			 	 	 	 	 		  			