#include <bits/stdc++.h>
using namespace std;
void GO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
const long long INF = 1e9 + 7;
const long long mod = (1e9) + 7;
const int maxn = (int)5e3 + 1;
const long double PI = acos(-1.0);
const long double eps = 0.000000001;
mt19937 rnd(time(0));
void solve() {
  long long n, k;
  cin >> n >> k;
  long long mn = INF;
  for (long long i = 1; i <= sqrtl(n); ++i) {
    if (n % i) continue;
    long long z = i, ost = n / i;
    long long x = z * k + ost;
    if ((x / k) * (x % k) == n) mn = min(mn, x);
    z = n / i, ost = i;
    x = z * k + ost;
    if ((x / k) * (x % k) == n) mn = min(mn, x);
  }
  cout << mn;
}
signed main() {
  GO();
  int Q = 1;
  while (Q--) {
    solve();
  }
}
