#include <bits/stdc++.h>
using namespace std;
long long n, k, x, a, b, ans = 1e9, tmp;
const int N = 1e9;
int main() {
  cin >> n >> k;
  x = min(n, k);
  for (long long i = (1); i < (x + 1); i++) {
    if (n % i == 0) {
      b = i;
      a = n / b;
      tmp = k * a + b;
      if ((tmp / k) * (tmp % k) == n) ans = min(ans, tmp);
    }
  }
  cout << ans;
  return 0;
}
