a = []
b= []
n, m = 0, 0
x, y = 0, 0
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 * 10 + y)
else:
    print(x)
