#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, i, tmp, r, x;
  unsigned long long int min = 999999999;
  cin >> n >> k;
  for (i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      x = (k * i) + n / i;
      if ((x / k) * (x % k) == n) {
        if (x < min) min = x;
      }
      x = k * n / i + i;
      if ((x / k) * (x % k) == n) {
        if (x < min) min = x;
      }
    }
  }
  cout << min << endl;
  return 0;
}
