(define (main args) (let* ([n (read)] [k (read)]) (print (cond [(or (zero? k) (> k n)) 0] [(= (* 2 k) (+ n 1)) (- n 1)] [else (- n 2)]))) 0)