#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, mn = 9000000000000000000LL;
  cin >> n >> k;
  vector<pair<long long, long long>> v;
  vector<long long> v1;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back({i, n / i});
    }
  }
  for (auto it : v) {
    long long x = it.first * k + it.second;
    long long y = it.second * k + it.first;
    if ((x / k) * (x % k) == n) {
      v1.push_back(x);
    } else if ((y / k) * (y % k) == n) {
      v1.push_back(y);
    }
  }
  sort(v1.begin(), v1.end());
  cout << v1[0] << endl;
}
