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

l1 = raw_input().split()
l2 = raw_input().split()

lista = []

for i in xrange(len(l1)):
    for j in xrange(len(l2)):
        if l1[i] == l2[j]:
            lista.append(int(l1[i]))
        else:
            lista.append(int(l1[i]+l2[j]))
            lista.append(int(l2[j]+l1[i]))
print min(lista)