#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  long long smallest = LLONG_MAX;
  for (int i = 1; i < k; i++) {
    if (n % i == 0) {
      smallest = min(smallest, (n / i * k + i));
    }
  }
  cout << smallest;
  return 0;
}
