let () = let n, k = Scanf.scanf "%d %d " (fun n k -> n, k) in if k <= 0 || k > n || n = 1 then print_endline "0" else if n mod 2 = 0 then Printf.printf "%d\n" (n - 2) else Printf.printf "%d\n" (n - if (n + 1) / 2 = k then 1 else 2)