import math N, K = map(int, input().split()) Ints = [i for i in range(N)] Primefactors = [0]*N Factors = [1]*N for i in range(2, math.floor(N)+1): if Ints[i] == 1: continue for j in range(1, N): if i*j < N: t = 1 while Ints[i*j]%i == 0: Ints[i*j] //= i Primefactors[i*j] += 1 t += 1 Factors[i*j] *= t else: break nowfactors=ans=1 for i in range(2,N): if Primefactors[math.gcd(i,N)] >= K: if Factors[i] > nowfactors: ans = i nowfactors = Factors[i] print(ans)