#include <bits/stdc++.h>
int main() {
  int64_t n, k;
  std::cin >> n >> k;
  int64_t prod = n * k;
  int64_t best_x = prod + 1;
  for (int i = 1; i < k; i++) {
    int64_t den = i;
    if (prod % den == 0) {
      int64_t x = prod / den + den;
      if ((x - i) % k == 0) {
        if (x < best_x) best_x = x;
      }
    }
  }
  std::cout << best_x << std::endl;
  return 0;
}
