#coding: utf-8

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

seq1_int = map(int, seq1)
seq2_int = map(int, seq2)

min_seq1 = min(seq1_int)
min_seq2 = min(seq2_int)

if min_seq1 not in seq2_int and min_seq2 not in seq1_int:
    min = min(min_seq1, min_seq2)
    max = max(min_seq1, min_seq2)
    print "%d%d" % (min, max)

elif min_seq1 in seq2_int:
    print min_seq1

else:
    if min_seq1 in seq2_int:
        print min_seq1
    else:
        print min_seq2