import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(), m = sc.nextLong(), a = n, b = m, tmp = n%m; while(tmp > 0){ a = b; b = tmp; tmp = a % b; } System.out.println((n/b)-1); } }