o = 0
i = 0
y = []
x = []
v_vod = input().split()
n = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]
if 1 in n or m:
    print(1)
else:
    res_x = str(min(n))
    res_y = str(min(m))
    result = int(res_x + res_y)
    print(result)