#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define INF (1 << 30) #define INFLL (1LL << 60) #define FOR(i,a,b) for(ll i = (a);i<(b);i++) #define REP(i,a) FOR(i,0,(a)) #define MP make_pair ll gcd(int a, int b){ int r; while((r = a % b) != 0){ a = b; b = r; } return b; } ll lcm(int a, int b){ return (a * b) / gcd(a, b); } int main() { ll n, d; cin >> n >> d; ll ret = lcm(n, d); cout << ret / d - 1 << endl; return 0; }