#include long gcd(long x,long y) { long r; if(y>x){ r=x; x=y; y=r; } while(y>0){ r=x%y; x=y; y=r; } return x; } long lcm(long x,long y) { return x*y/gcd(x,y); } int main(void) { long n,d; scanf("%ld%ld",&n,&d); printf("%ld",lcm(n,d)/d-1); return 0; }