#include <bits/stdc++.h>
using namespace std;
long long a[1000005];
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  int r = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      a[r] = i;
      r++;
      a[r] = n / i;
      r++;
    }
  }
  long long mx = 1e15;
  for (int i = 0; i < r; i += 2) {
    long long s = a[i] * k + a[i + 1];
    if (s % k == 0 || a[i + 1] >= k) {
      s = 1e15;
    }
    mx = min(mx, s);
    s = a[i + 1] * k + a[i];
    if (s % k == 0 || a[i] >= k) {
      s = 1e15;
    }
    mx = min(mx, s);
  }
  cout << mx;
  return 0;
}
