This page is still under construction.

Parts of this page are still being built. What you see may change.

Fitness Club

Interview

Time limit2sMemory limit1024 MB

Summary
Assign k lockers to n groups of visitors so that the number of lockers still locked at day's end is maximized, given each group's counts of visitors who lock and do not lock.
Level

Medium6 of 10

Topics
Dynamic programming, Greedy, Implementation
Solved
No attempts yet

Problem

Fitness clubs have recently become very popular among the residents of the capital of Flatland. People go to such clubs after work to stay in good physical shape. At the fitness club <>, each visitor is assigned one of kk lockers for the duration of the visit, where they can put their belongings during the workout.

During the day, nn workouts take place at the fitness club. Each visitor arrives at the start of some workout (at which point they receive a locker key) and leaves immediately after it ends (at which point they return the locker key). We may assume that all visitors who have finished a workout leave before all visitors who have arrived for the next workout.

Some visitors lock their locker when leaving, while others do not. Since all visitors of the fitness club have been coming for quite a long time, the staff knows for each of them whether they will lock their locker when leaving. Thus, for each workout two numbers are known: the number aia_i of visitors who will lock their locker and the number bib_i of visitors who will not.

At the start of the day, all kk lockers are locked. Naturally, the club staff would like as many lockers as possible to be locked at the end of the day as well, since then there will be less work when preparing for the next day. To achieve this goal, the staff can hand out locker keys to visitors in an arbitrary manner. For example, it makes sense to give the key to an open locker to someone who will definitely lock it.

Find the maximum number of lockers that will end up locked if the fitness club staff acts optimally.

Input

The first line of the input file contains two integers: nn (1≤n≤1001 \le n \le 100) and kk (1≤k≤10001 \le k \le 1000). Each of the following nn lines contains two integers aia_i and bib_i (0≤ai,bi≤k0 \le a_i, b_i \le k, ai+bi≤ka_i + b_i \le k).

Output

Output a single number to the output file: the answer to the problem.

Hint

Number the lockers from 11 to 44. To the visitors who came for the first workout, hand out keys as follows: to the one who will lock, the key to locker 11; to those who will not lock, the keys to lockers 22 and 33. To the visitors who came for the second workout, hand out keys as follows: to the one who will lock, number 22; to the one who will not lock, number 33. As a result, only locker number 33 remains open after the end of the day.

Examples1

  1. Example 1

    Input
    2 4
    1 2
    1 1
    
    Expected output
    3