n, m = map(int, raw_input().split())
a = map(int, raw_input().split())
a = set(a)
b = map(int, raw_input().split())
b = set(b)
c = a & b
if len(c) > 0:
    print min(c)
else:

    a = list(a)
    a.sort()
    b = list(b)
    b.sort()
    s = str(min(a[0], b[0])) + str(max(a[0], b[0]))
    print s
