#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e17;
long long n, k, ans;
int main() {
  cin >> n >> k;
  ans = inf;
  for (int i = 1; i <= k - 1; ++i) {
    if (n % i == 0) {
      ans = min(ans, n / i * k + i);
    }
  }
  cout << ans;
}
