#include <bits/stdc++.h>
using namespace std;
int main() {
  uint64_t n, k;
  cin >> n >> k;
  vector<uint64_t> res(k, 1ULL << 60);
  for (uint64_t xi = 1; xi < k; ++xi) {
    if (n % xi != 0) continue;
    uint64_t t = n / xi;
    res[xi] = t * k + xi;
  }
  cout << *(min_element(res.begin(), res.end()));
  return 0;
}
