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()))

if 0 in a:
    ind = a.index(0)
    del a[ind]
    
x = min(a)
y = min(b)
   
if x != y:
    print(x * 10 + y)
else:
    print(x)
