#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  int ret = (1 << 30);
  for (int i = 1; i <= n; ++i) {
    if (n % i == 0) {
      int first = i, b = n / i;
      int second = k * first + b;
      if (second % k == b) {
        ret = min(ret, second);
      }
    }
  }
  cout << ret << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
