#include using namespace std; int n, m; int main() { cin >> n >> m; cout << n / __gcd(n, m) - 1 << endl; return 0; }