#include using namespace std; typedef long long int ll; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n,d; cin >> n >> d; ll l=n*d/__gcd(n,d); cout << l/d-1 << endl; }