Under construction

Still being built. Things may change

Bus

Interview

Time limit1sMemory limit1024 MB

Summary
Track how many passengers are on the bus after each stop and report the largest number of them that exceeds the seat count K.
Level

Easy3 of 10

Topics
Implementation, Simulation, Array
Solved
No attempts yet

Problem

A bus route consists of NN stops. The bus reaches the first stop straight from the depot, so it is always empty when it arrives there. After that, at each stop some passengers board the bus and some passengers get off.

Passengers prefer to sit down: whenever there is a free seat on the bus a passenger will take it, and passengers stand only when there is not a single free seat left. The bus has KK seats in total.

Given how many passengers board and get off at every stop, find the greatest number of passengers that ever have to stand in the bus at one time.

Input

The first line contains two integers NN and KK — the number of stops on the route and the number of seats in the bus.

Each of the next NN lines contains two integers aia_i and bib_i: aia_i is the number of passengers boarding at that stop, and bib_i is the number getting off.

Output

Print a single integer — the maximum number of passengers that ever have to stand in the bus at one time.

Constraints

  • 2≤N≤10002 \le N \le 1000
  • 0≤ai,bi,K≤10000 \le a_i, b_i, K \le 1000

Examples2

  1. Example 1

    Input
    4 10
    5 0
    5 2
    10 5
    0 13
    
    Expected output
    3
    
  2. Example 2

    Input
    5 12
    7 0
    4 3
    8 4
    5 5
    0 12
    
    Expected output
    0