#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define pi M_PI typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVI; typedef pair P; typedef pair PL; int gcd(int x, int y){ if (y == 0) return x; return gcd(y, x%y); } int main(){ int n, d; cin >> n >> d; int ans; if (n == d) ans = 0; else ans = n/gcd(n,d)-1; cout << ans << endl; return 0; }