#include using namespace std; int main() { long N, D; cin >> N >> D; cout << lcm(N, D) / D - 1 << "\n"; }