import java.util.Scanner; class Main{ public static 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; } public static long lcm(long x,long y) { return x*y/gcd(x,y); } public static void main(String[] args) { Scanner sc=new Scanner(System.in); long n=sc.nextLong(),d=sc.nextLong(); sc.close(); System.out.print(lcm(n,d)/d-1); } }