#include <bits/stdc++.h>
using namespace std;
vector<int> v;
stack<int> st;
queue<int> qu;
priority_queue<int> pq;
set<int> sett;
const int MOD = 1e9 + 7;
int mx = 100000000;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  int mn = INT_MAX;
  for (int i = 1; i < k; i++) {
    if (n % i == 0) {
      int x = floor((n / i)) * k + i;
      mn = min(x, mn);
    }
  }
  cout << mn << endl;
  return 0;
}
