#include using namespace std; int main() { int N, K; cin >> N >> K; vector fact(N), num(N, 1); for (int i = 1; i < N; i++) { for (int j = 1; i * j < N; j++) { fact[i * j]++; } } num[1] = 0; for (int i = 2; i * i < N; i++) { if (num[i] == 1) { 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] > max) { res = i, max = fact[i]; } } cout << res << endl; }