#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n;
  int k, j;
  cin >> n >> k;
  j = k;
  if (n > k) {
    while (n % (j - 1) != 0) {
      j--;
    }
    cout << (k * n / (j - 1)) + (j - 1);
  } else if (n < k) {
    cout << n + k;
  } else {
    if (k % 2 == 0)
      cout << (k * 2) + (k / 2);
    else
      cout << (k * n) + 1;
  }
  return 0;
}
