#include #define rep(i, a, n) for(int i = a; i < n; i++) #define repp(i, n) rep(i, 0, n) #define repb(i, a, b) for(int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define int long long using namespace std; typedef pair P; int gcd(int a, int b){ if(a < b) swap(a, b); if(b == 0) return a; return gcd(b, a % b); } signed main(){ int n, d; cin >> n >> d; cout << n / gcd(n, d) - 1 << endl; }