#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int temp1 = 0;
  for (int i = k - 1; i >= 1; i--) {
    if (n % i == 0) {
      temp1 = i;
      break;
    }
  }
  long long ans = (n / temp1) * k + temp1;
  printf("%lld\n", ans);
}
