#include <bits/stdc++.h>
using namespace std;
template <typename T>
vector<T> &operator--(vector<T> &v) {
  for (auto &i : v) --i;
  return v;
}
template <typename T>
vector<T> &operator++(vector<T> &v) {
  for (auto &i : v) ++i;
  return v;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &i : v) is >> i;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
  for (auto &i : v) os << i << ' ';
  return os;
}
template <typename T, typename U>
pair<T, U> &operator--(pair<T, U> &p) {
  --p.first;
  --p.second;
  return p;
}
template <typename T, typename U>
pair<T, U> &operator++(pair<T, U> &p) {
  ++p.first;
  ++p.second;
  return p;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
  return mp(a.first - b.first, a.second - b.second);
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
  return mp(a.first + b.first, a.second + b.second);
}
template <typename T, typename U>
void umin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
void umax(T &a, U b) {
  if (a < b) a = b;
}
bool prime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long fact(long long x) {
  long long ans = 1;
  for (long long i = 2; i <= x; i++) ans *= i;
  return ans;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  long long ans = LLONG_MAX;
  for (long long i = 1; i <= (long long)sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i <= k - 1) ans = min(ans, k * i + (n / i));
      if (i <= k - 1) ans = min(ans, k * (n / i) + i);
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
