import bisect def makediv(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] n, m = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) assert 1 <= n <= 30000 assert 1 <= m <= 30000 for i in range(n): assert 1 <= a[i] <= 30000 for i in range(m): assert 1 <= b[i] <= 30000 for i in range(n-1): assert a[i] < a[i+1] for i in range(m-1): assert b[i] < b[i+1] a2 = [a[i] * a[i] for i in range(n)] b2 = [b[i] * b[i] for i in range(m)] if a[0] != 1 or b[0] != 1: print(1) exit() c = [0] * 40000 for i in range(n): c[a[i]] = 1 for i in range(m): c[b[i]] = 1 v = 0 for i in range(1, 40000): if c[i] == 0: v = i ** 2 break k = v while True: mode = 0 for i in makediv(k): j = k // i ar = 0 for x in range(n): if a[x] ** 2 <= i < (a[x] + 1) ** 2: ar = 1 break if ar == 0: continue ar = 0 for y in range(m): if b[y] ** 2 <= j < (b[y] + 1) ** 2: ar = 1 break if ar == 1: mode = 1 break if not mode: break k += 1 print(k)