This page is still under construction.

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

Lifeguards (Platinum)

Time limit2sMemory limit512 MB

Summary
Fire exactly K of N lifeguard shifts to maximize the total time covered by at least one remaining shift.
Level

Hard8 of 10

Topics
Dynamic programming, Sorting, Greedy, Intervals
Solved
No attempts yet

Problem

Farmer John opened a swimming pool for his cows, figuring it will help them relax and produce more milk.

To keep the pool safe he hires NN cows as lifeguards. Each lifeguard works one shift that covers a contiguous stretch of the day. The pool is open from time 00 until time 10910^9 every day, so a shift is given by two integers, the time the cow starts and the time she ends. A lifeguard who starts at t=4t = 4 and ends at t=7t = 7 watches three units of time. The endpoints are points in time, so a point by itself has no length.

Farmer John hired KK more lifeguards than he can pay for, so he must fire exactly KK of them. A stretch of time is watched when at least one of the remaining lifeguards is on duty. Find the largest total amount of time the remaining shifts can still watch.

Input

The first line contains NN and KK (K≤N≤100000K \leq N \leq 100000, 1≤K≤1001 \leq K \leq 100).

Each of the next NN lines contains the start time and the end time of one lifeguard's shift, two integers between 00 and 10910^9. The start time is smaller than the end time. The 2N2N times in the input are all distinct. Shifts of different lifeguards may overlap.

Output

Print on one line the largest total amount of time that can be watched after Farmer John fires exactly KK lifeguards.

Hint

In the first sample Farmer John should fire the lifeguard working from 11 to 88 and the one working from 77 to 1515. The shift from 22 to 1414 that remains watches 12 units of time.

Examples2

  1. Example 1

    Input
    3 2
    1 8
    7 15
    2 14
    
    Expected output
    12
    
  2. Example 2

    Input
    5 2
    0 10
    20 23
    30 31
    40 46
    50 61
    
    Expected output
    27