#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long x, q, b;
  for (int i = k - 1; i >= 1; i--) {
    x = n / i * k + i;
    q = x % k;
    b = x / k;
    if (q * b == n) return cout << x, 0;
  }
}
