#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int su(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int dig(int n) {
  int cnt = 0;
  while (n > 0) {
    n /= 10;
    cnt++;
  }
  return cnt;
}
int divs(int n) {
  int cnt = 0;
  for (int x = 1; x * x <= n; x++) {
    if (n % x == 0) {
      cnt++;
      if (n / x != x) cnt++;
    }
  }
  return cnt;
}
int isprime(int n) {
  if (n < 2) return false;
  for (int x = 2; x * x <= n; x++)
    if (n % x == 0) return false;
  return true;
}
const int mod = 1000000007;
struct abc {
  long long int val;
  long long int index;
};
bool compare(abc x1, abc x2) {
  if (x1.val == x2.val) return (x1.index > x2.index);
  return (x1.val < x2.val);
}
const int N = 100;
long long int b[2000];
int main() {
  long long int n, k, p = 0;
  cin >> n >> k;
  for (p = k - 1; p > 0 && n % p; p--)
    ;
  cout << (n / p) * k + p;
}
