Under construction

Still being built. Things may change

Raffle Tickets

Interview

Time limit1sMemory limit128 MB

Summary
Buy tickets from baskets with known winning and losing counts to guarantee at least g wins with the fewest tickets.
Level

Medium5 of 10

Topics
Dynamic programming
Solved
No attempts yet

Problem

At a school event there are nn baskets, and each basket is filled with a number of raffle tickets. Some tickets are winning: drawing a winning ticket earns the right to skip one class hour without an excuse.

Kozik has decided that he wants to skip gg hours this school year, so he needs to end up holding at least gg winning tickets. He will buy tickets from the baskets, but he cannot choose which individual tickets he receives, so he wants to be certain: no matter which tickets happen to come out, the tickets he buys must include at least gg winning ones. Because money is tight, he wants to buy as few tickets as possible.

Kozik knows exactly how many winning and how many losing tickets each basket holds. When he takes tickets from a basket, assume the worst case: every losing ticket in that basket comes out before any winning one. So to be guaranteed kk winning tickets from a basket that holds ww winning and pp losing tickets (with k≤wk \le w), he must take p+kp + k tickets from it.

Find the smallest total number of tickets Kozik must buy so that he is guaranteed at least gg winning tickets.

Input

The first line contains two integers nn and gg (1≤n≤100001 \le n \le 10000, 1≤g≤10001 \le g \le 1000): the number of baskets and the number of hours Kozik wants to skip.

Each of the next nn lines describes one basket with two integers wiw_i and pip_i (0≤wi≤1090 \le w_i \le 10^9, 0≤pi≤1090 \le p_i \le 10^9): the number of winning and losing tickets in the ii-th basket.

Output

Print a single integer: the minimum number of tickets Kozik must buy to be guaranteed at least gg winning tickets. If this is impossible (the baskets together hold fewer than gg winning tickets), print the word NIE instead.

Examples2

  1. Example 1

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

    Input
    1 5
    2 3
    
    Expected output
    NIE