open System let ri () = stdin.ReadLine() |> int let ria () = stdin.ReadLine().Split() |> Array.map int let rec gcd s t = match s with | 0 -> t | _ -> gcd (t%s) s type Sol() = member this.Solve() = let (N,D) = stdin.ReadLine().Split([|' '|],StringSplitOptions.RemoveEmptyEntries) |> Array.map int |> (fun a -> (a.[0],a.[1])) N / (gcd N D) - 1 |> printfn "%d" let mySol = new Sol() mySol.Solve()