n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
v1 = min(a)
v2 = min(b)
if v1 == v2:
    print(v1)
else:
    print(min(v1,v2), end = '')
    print(max(v1,v2))
