#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = k - 1; i > 0; i--) {
    if (n % i == 0) {
      cout << (n / i) * k + i << endl;
      break;
    }
  }
}
