#include <bits/stdc++.h>
using namespace std;
vector<int> get_divs(int n) {
  vector<int> out;
  out.push_back(1);
  out.push_back(n);
  for (int i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      out.push_back(i);
      if (i * i != n) out.push_back(n / i);
    }
  return out;
}
int main() {
  int n, k;
  cin >> n >> k;
  auto divs = get_divs(n);
  int min_x = 2e9;
  for (const auto &a : divs)
    if (n / a < k) {
      int x = a * k + n / a;
      min_x = min(x, min_x);
    }
  cout << min_x << '\n';
}
