n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
o = [x for x in a if x in b]
if o:
    print(min(o))
else:
    am = min(a)
    bm = min(b)
    print(min(am, bm), max(am, bm), sep = '')