import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int D = sc.nextInt(); int a=N; int b=D; while(b!=0){ int t=a%b; a=b; b=t; } int r=N/a-1; System.out.println(r); } }