n, m = list(map(int,input().split()))
a = set(map(int,input().split()))
b = set(map(int,input().split()))
if a & b:
    print(min(a & b))
else:
    if min(a)< min(b):
        print(str(min(a)) + str(min(b)))
    else:
        print(str(min(b)) + str(min(a)))
   		  				   	  			  	 	