#include using namespace std; int main() { int N, D; cin >> N >> D; cout << N / __gcd(N, D) - 1 << endl; }