#include <bits/stdc++.h>
typedef long long ll;
int main() {
    ll n, k, ans = 0x3f3f3f3f3f3f3f3f;
    std::cin >> n >> k;
    for (ll b = k - 1; b >= 1; b--) {
        if (n % b == 0) {
            ll a = n / b;
            ans = std::min(ans, a * k + b);
        }
    }
    std::printf("%lld\n", ans);
    return 0;
}