#include <bits/stdc++.h>
int main() {
  long long int n, k, x, i, s, a, b;
  scanf("%lld %lld", &n, &k);
  for (i = k - 1; i >= 1; i--) {
    if (n % i == 0) {
      a = n / i;
      b = i;
      break;
    }
  }
  s = a * k + b;
  printf("%lld\n", s);
  return 0;
}
