#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int ans = INT_MAX;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      int div = i;
      int mod = n / i;
      int x = k * div + mod;
      if ((x / k) == div && (x % k) == mod) ans = min(ans, x);
      swap(div, mod);
      x = k * div + mod;
      if ((x / k) == div && (x % k) == mod) ans = min(ans, x);
    }
  }
  cout << ans;
}
