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