n, m = map(int, input().split())
a = set(int(x) for x in input().split())
b = set(int(x) for x in input().split())
if (a&b):
    print(min(a&b))
else:
    a = min(a)
    b = min(b)
    print(min(a,b) * 10 + max(a,b))
