#include using namespace std; int gcd(int m,int n){ while(n != 0){ int tmp = n; n = m % n; m = tmp; } return m; } int main(){ int n,d; cin >> n >> d; cout << n / gcd(n,d) - 1 << endl; }