n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))

intersection = list(set(a) & set(b))
if intersection:
    print(min(intersection))
else:
    x = a[0]
    y = b[0]
    if x > y:
        x, y = y, x
    print('%s%s' % (x, y))
