#include using namespace std; typedef long long ll; long gcd(long m, long n) { if (m < n) swap(m, n); long r = m % n; if (!r) return n; else { m = n; n = r; return gcd(m, n); } } long lcm(long m, long n) { return (m * n / gcd(m, n)); } int main(void) { #ifdef DEBUG freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); long N, D, ans; cin >> N >> D; ans = lcm(N, D) / D - 1; cout << ans << endl; return 0; }