#include <bits/stdc++.h>
using namespace std;
int n;
int k;
int x = 0;
int z;
vector<int> a;
int main() {
  cin >> n;
  cin >> k;
  for (int i = 1; i < k; i++)
    if (n % i == 0) a.push_back(k * (n / i) + i);
  int ans = a[0];
  for (int i = 0; i < a.size(); i++)
    if (a[i] < ans) {
      ans = a[i];
    }
  cout << ans << endl;
  return 0;
}
