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