#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T>
ostream& operator<<(ostream& o, vector<T> x) {
  for (auto it : x) o << it << ' ';
  return o;
}
template <typename T>
istream& operator>>(istream& i, vector<T>& x) {
  for (auto& it : x) i >> it;
  return i;
}
template <typename T1, typename T2>
void chkmin(T1& a, T2 b) {
  a > b ? a = b : 0;
}
template <typename T1, typename T2>
void chkmax(T1& a, T2 b) {
  a < b ? a = b : 0;
}
const int INF = 1000000007;
const int INF2 = 100000000000000007;
const int mINF = 1e16;
const int MOD1 = 998244353;
const int MOD = 1000000007;
const int SIZE = 200010;
const int base = 53;
const long double eps = 1e-6;
const long double pi = acosl(-1.0);
int add(int a, int b) { return ((a + b) % MOD + MOD) % MOD; }
int mult(int a, int b) { return (a * b) % MOD; }
int binpow(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1) res = mult(res, a);
    a = mult(a, a);
    n >>= 1;
  }
  return res;
}
int binpow1(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1) {
      res *= a;
    }
    a *= a;
    n >>= 1;
  }
  return res;
}
int inv(int a) { return binpow(a, MOD - 2); }
int del(int a, int b) { return mult(a, inv(b)); }
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int sqr(int x) { return x * x; }
int n, k, maxost, n1;
vector<int> divs;
void rec(int pos, int x) {
  if (x >= k) return;
  chkmax(maxost, x);
  if (pos < divs.size()) {
    rec(pos + 1, x);
    rec(pos + 1, x * divs[pos]);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  maxost = 1;
  n1 = n;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) n /= i, divs.push_back(i);
  }
  if (n != 1) divs.push_back(n);
  rec(0, 1);
  cout << k * n1 / maxost + maxost;
  return 0;
}
