# Search for Pretty Integers

n, m = map(int,raw_input().split())

a = list(map(int, raw_input().split()))
b = list(map(int, raw_input().split()))

for i in range(1,10):
    if i in a and i in b:
        print(i)
        exit(0)

x = min(a)
y = min(b)
print('%d%d'%(min(x,y),max(x,y)))
  					  	 	  	  	      					 	