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