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