n,m = map(int,input().split(' '))

n1 = input().split(' ')

m1 = input().split(' ')

lis = 100

for i in range(100):
	st = str(i)
	if len(st) == 1:
		if (st in m1) and (st in n1) and (i<lis):
			lis = i
	else:
		st1 = st[0]
		st2 = st[1]
		if (((st1 in n1) and (st2 in m1)) or ((st1 in m1) and (st2 in n1))) and (i<lis):
			lis = i
print(lis)			
			
			