#coding: utf-8

n_m = raw_input().split()
seq1 = raw_input().split()
seq2 = raw_input().split()

min_seq1 = min(map(int, seq1))
min_seq2 = min(map(int, seq2))

if min_seq1 == min_seq2:
    print min_seq1

else:
    min = min(min_seq1, min_seq2)
    max = max(min_seq1, min_seq2)
    print "%d%d" % (min, max)
