#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int MAX = 1e6 + 10;
long long int solve() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> vec;
  for (int i = ceil(1.0 * n / (k - 1)); i < n + 1; i++) vec.push_back(i);
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i] == 0 || n % vec[i] != 0) continue;
    if (n / vec[i] < (k) && n / vec[i] > 0)
      return cout << vec[i] * k + n / vec[i], 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int t;
  t = 1;
  while (t--) solve();
  return 0;
}
