open System let ri () = stdin.ReadLine() |> int let ria () = stdin.ReadLine().Split() |> Array.map int let rec gcd a b = if a = 0 then b else gcd (b%a) a type Sol() = member this.Solve() = let (N,D) = stdin.ReadLine().Split(' ') |> Array.map int |> (fun a -> (a.[0],a.[1])) N / (gcd N D) - 1 |> printfn "%d" () let mySol = new Sol() mySol.Solve()