(define (main args)
  (let* ([n (read)]
         [d (read)])
    (print
     (let loop ([c n]
                [tm 0]
                [km -1000000000])
       (cond [(zero? c) (max tm km)]
             [else (let* ([t (read)]
                          [k (read)])
                     (loop (- c 1)
                           (max
                            (+ tm t)
                            (- (+ km t) d))
                           (max
                            (+ km k)
                            (- (+ tm k) d))))]))))
  0)