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