n,m = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = min(a)
y = min(b)
if (x == y):
    print(x)
else:
    print(min(x, y), end = '')
    print(max(x, y))