#include <bits/stdc++.h>

using namespace std;

#define FILE(name) if (fopen(name".inp", "r"))  freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
#define ll long long
#define el "\n"
#define ex " "
const long long maxn = 1e5 + 5;
const long long mod = 1e9 + 7;

vector <ll> nt = {2,3,5,7,11,13,17,23,29,31,37} ;
ll n,k;


int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    FILE("test");
    cin >> n  >> k;

ll i=2;
    set <ll> s;
    unordered_map <ll,ll> mp;

    while (i<=trunc(sqrt(n))) {
        while (n % i == 0) {
            s.insert(i);
            mp[i]++;
            n/=i;
        }
        i++;
    }
    if (n >  1) {s.insert(n); mp[n]++; }
    ll sluoc = 1 ;
    
    for (ll x:s)
        sluoc *= (mp[x] + 1);

    if (sluoc * 2 == k)
        for (ll i : nt)
    if (mp[i] == 0) return cout<<i,0;

    else {
        ll sluocmoi = 1;
        for (ll i:nt)  {
            sluocmoi = sluoc + sluoc / (mp[i] + 1);


            if (sluocmoi == k) return cout<<i,0;
        }
    }

    cout<<-1;



    return 0;
}
