#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int limit = int(sqrt(n));
  int x_div_k, x, temp;
  int smallest = numeric_limits<int>::max();
  for (int x_mod_k = 1; x_mod_k <= limit; x_mod_k++) {
    if (n % x_mod_k == 0) {
      x_div_k = int(n / x_mod_k);
      if (x_mod_k < k) {
        x = x_div_k * k + x_mod_k;
        if (x < smallest) smallest = x;
      }
      if (x_div_k < k) {
        x = x_mod_k * k + x_div_k;
        if (x < smallest) smallest = x;
      }
    }
  }
  cout << smallest;
  return 0;
}
