let [| n; k |] = stdin.ReadLine().Split() |> Array.map int if n >= k then k - 1 else -1 |> printfn "%d"