#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 2;
const int maxn = 2e5 + 10;
const int maxq = 1e3 + 10;
const int alf = 26;
const int dlm = 1e9 + 7;
const long long mod = 998244353;
string O[] = {"YES", "NO", "Yes", "No"};
int main() {
  int n, k;
  cin >> n >> k;
  int ans = inf;
  for (int i = 1; i < k; i++) {
    if (n % i != 0) continue;
    ans = min(ans, (n / i) * k + i);
  }
  cout << ans;
}
