#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, ans;
  cin >> a >> b;
  if (a > b) {
    for (int x = b - 1; x >= 0; x--) {
      if (a % x == 0) {
        int d = a / x;
        if (d < b) {
          int r = max(d, x);
          int e = min(d, x);
          ans = e * b + r;
        } else {
          ans = d * b + x;
        }
        break;
      }
    }
  } else if (b > a) {
    ans = b + a;
  } else {
    ans = a * b + 1;
  }
  cout << ans;
}
