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