sub gcd{my($a,$b)=@_;$a?gcd($b%$a,$a):$b} ($n,$d)=glob<>; print $n/gcd($n,$d)-1