#coding: utf-8

n_m = raw_input().split()
seq1 = map(int, raw_input().split())
seq2 = map(int, raw_input().split())

min1 = min(seq1)
min2 = min(seq2)

repetidos = filter(lambda x: x in seq2, seq1)

if len(repetidos) > 0:
    print min(repetidos)

else:
    if min1 < min2:
        print "%d%d" % (min1, min2)
    else:
        print "%d%d" % (min2, min1)
