#include using namespace std; using ll = long long; ll calc(ll m, ll n, ll sqn = -1) { ll d = m / sqrt(n); if (sqn != -1) { d = m / sqn; } return m - d; } int main () { ll N, M; cin >> N >> M; if (N == 1) { puts("-1"); return 0; } ll sqn = 0; while (sqn * sqn < N) sqn ++; if (sqn * sqn != N) sqn = -1; ll ok = (ll)1e7, ng = -1; while (abs(ok - ng) > 1) { ll mu = (ok + ng) / 2; if (calc(mu, N, sqn) >= M) { ok = mu; } else { ng = mu; } } cout << ok << endl; }