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