#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    map<int, int> mp;
    for (int i = 2, j = n; j != 1; i++) {
        while (j % i == 0) {
            mp[i]++;
            j /= i;
        }
    }
    int num = 0, ans = 0;
    for (int i = 2; i < n; i++) {
        map<int, int> tmp;
        for (int j = 2, k = i; k != 1; j++) {
            while (k % j == 0) {
                tmp[j]++;
                k /= j;
            }
        }
        int puni = 0, muni = 0;
        for (auto &p : tmp) {
            muni += p.second;
        }
        for (auto &p : mp) {
            puni += min(p.second, tmp[p.first]);
        }
        if (k <= puni && num < muni) {
            num = muni;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}