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