#include <bits/stdc++.h>
using namespace std;
int A = INT_MAX;
int main() {
  int n, m, k, x, c = 0, i, j;
  cin >> n >> k;
  long long a = n * k;
  for (i = 1; i < k; i++) {
    if (n % i == 0) {
      x = ((n * k) / i);
      A = min(A, x + i);
    }
  }
  cout << A << endl;
}
