#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 7;
const int linf = (int)1e9 + 7;
const int none = (int)-5489548;
const int mod = (int)3 * 1e4;
using namespace std;
int n, k;
int ok(int x) {
  long long ans = (x / k) * 1ll * (x % k);
  if (ans != n) return 0;
  return 1;
}
int main() {
  cin >> n >> k;
  for (int i = k - 1; i > 0; i--) {
    if (n % i == 0) {
      cout << i + (n / i) * 1ll * k;
      return 0;
    }
  }
}
