#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const unsigned int UINF = 0xffffffff;
void print_array(int v[], int n) {
  for (int i = int(0); i < int(n); i++) cout << v[i] << ' ';
  cout << endl;
}
void print_vector(vector<int> V) {
  vector<int>::iterator it;
  for (auto v : V) cout << v << ' ';
  cout << endl;
}
void print_array_pairs(pair<int, int> v[], int n) {
  for (int i = int(0); i < int(n); i++)
    cout << '(' << v[i].first << ", " << v[i].second << ") ";
  cout << endl;
}
void print_vector_pairs(vector<pair<int, int> > P) {
  vector<pair<int, int> >::iterator it;
  for (auto v : P) cout << '(' << v.first << ", " << v.second << ") ";
  cout << endl;
}
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int n, k, ans = INF;
  cin >> n >> k;
  for (int rest = int(1); rest < int(k); rest++)
    if (n % rest == 0) ans = min(ans, n / rest * k + rest);
  cout << ans << "\n";
  return 0;
}
