import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long N = sc.nextInt(); long D = sc.nextInt(); long ans = 0; long gcd = gcd(N,D); N *= D / gcd; System.out.println(N / D - 1); } static long gcd(long a, long b) { if(a < b) return gcd(b,a); if(b == 0) return a; return gcd(b, a % b); } }