#include #include using namespace std; typedef long long ll; ll gcd(ll x, ll y) { if (x < y) swap(x, y); int tmp; while (y) { tmp = y; y = x % y; x = tmp; } return x; } ll lcm(ll x, ll y) { if (x < y) swap(x, y); return (x * y / gcd(x, y)); } int main(void) { int N, D; cin.tie(0); cin >> N >> D; cout << lcm(N, D)/D - 1 << endl; return 0; }