#include using namespace std; //最大公約数 int gcd(int n, int m) { if (m == 0)return n; return gcd(m, n%m); } //最小公倍数 int lcm(int n, int m) { int g = gcd(n, m); return n / g * m; } int main() { int n, d; cin >> n >> d; cout << n / gcd(n, d) - 1 << endl; }