#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9,
                inf = 1e18 + 7;
const long long infll = 1e18 + 7;
long long n, k, ans = infll;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q = 1;
  while (q--) {
    cin >> n >> k;
    for (long long i = 1; i < k; i++) {
      if (n % i == 0) {
        long long j = n / i;
        ans = min(ans, j * k + i);
      }
    }
    cout << ans;
  }
}
