Under construction

Still being built. Things may change

Stop the overtime!!!

Time limit1sMemory limit1024 MB

Summary
Given tasks with deadlines and work units, move up to K deadlines later by one day each to minimize the overtime hours needed, with five regular days per week.
Level

Medium7 of 10

Topics
Greedy, Sorting, Heap
Solved
No attempts yet

Problem

Junmin could not escape overtime before his discharge, so right before he left the unit he handed the remaining tasks to his junior soldier Minwook. Minwook received NN tasks in total. Task ii requires tit_i units of work and has deadline did_i. No two tasks have the same deadline.

Minwook starts working on Monday. Regular duty runs only from Monday to Friday, and overtime duty can be done on any day of the week. Each day allows at most one regular shift and at most one overtime shift. In each shift, Minwook picks one task he wants and completes 1 unit of work on it.

Junmin wants to change the deadlines without the officers noticing. Each change moves the deadline of one chosen task later by 1 day. He will make at most KK changes so that he is not caught. To hide the changes, Minwook finishes all tasks in the order of their original deadlines, from earliest to latest.

After making at most KK deadline changes, find the minimum number of overtime hours Minwook must work.

Input

The first line contains the number of tasks NN and the number of deadline changes KK, separated by a space. Each of the next NN lines contains the deadline did_i and the work amount tit_i of the ii-th task, separated by a space.

Output

Print the minimum overtime hours Minwook must work after changing deadlines at most KK times. If it is impossible to finish all tasks on time no matter what, print -1.

Constraints

1≤N≤200 0001 \le N \le 200\,000, 0≤K≤1090 \le K \le 10^9, 1≤di≤200 0001 \le d_i \le 200\,000, 1≤ti≤200 0001 \le t_i \le 200\,000, and di≠djd_i \neq d_j for 1≤i<j≤N1 \le i < j \le N. All input values are integers.

Examples2

  1. Example 1

    Input
    5 5
    2 1
    8 3
    6 1
    7 4
    10 1
    
    Expected output
    1
    
  2. Example 2

    Input
    3 0
    5 3
    3 5
    4 3
    
    Expected output
    -1