#include using namespace std; int main() { int N, K; cin >> N >> K; vector> fact(N + 1); vector num(N + 1, 1); for (int i = 1; i < N; i++) { for (int j = 1; j * j <= i; j++) { if (i % j) continue; fact[i].push_back(j); if (j * j != i) fact[i].push_back(i / j); } } num[1] = 0; for (int i = 2; i * i < N; i++) { if (num[i] != 1) continue; for (int j = 2; i * j < N; j++) num[i * j] = num[i] + num[j]; } int max = 0, res = 0; for (int i = 1; i < N; i++) { if (num[__gcd(i, N)] >= K && fact[i].size() > max) res = i, max = fact[i].size(); } cout << res << endl; }