PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000067. Hộp ghi hình (Entertainment Box)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Hộp ghi hình (Entertainment Box)

Entertainment Box

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A recording device has kk independent recording slots and nn TV shows, each running from time xix_i to yiy_i. One slot records one show at a time and may begin another exactly when the previous one ends. Count only completely recorded shows, each at most once. Find the maximum number of shows.

Input

The first line contains n,kn,k. Each of the next nn lines contains xi,yix_i,y_i.

Output

Print the maximum number of fully recordable shows.

Subtasks

  • Subtask 1 (20 points): 2≤n≤242\le n\le 24; 1≤k<n1\le k<n; 0≤xi<yi≤1090\le x_i<y_i\le10^9 for every ii.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le 2000; 1≤k<n1\le k<n; 0≤xi<yi≤1090\le x_i<y_i\le10^9 for every ii.
  • Subtask 3 (50 points): 2≤n≤1000002\le n\le 100000; 1≤k<n1\le k<n; 0≤xi<yi≤1090\le x_i<y_i\le10^9 for every ii.

Examples

Input

3 1
1 2
2 3
2 3

Output

2

Explanation

There is one recording slot. Record [1,2][1,2] and then one of the [2,3][2,3] shows; the slot becomes free exactly at time 22. The other show overlaps, so the answer is 22.