#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
int f[N], cnt = 0, n, k, ans = 1000000000;
void factor(int x) {
  for (int i = 1; i <= sqrt(x); i++)
    if (x % i == 0) {
      f[++cnt] = i;
      if (i * i != x) f[++cnt] = x / i;
    }
  sort(f + 1, f + cnt + 1);
}
int main() {
  cin >> n >> k;
  factor(n);
  for (int i = 1; i <= cnt && f[i] < k; i++)
    ans = min(ans, n / f[i] * k + f[i]);
  cout << ans << endl;
  return 0;
}
