Homework

Given n assignments split into two courses with release days and deadlines, simulate fixed tie-break rules over adaptive coin choices and find the maximum and minimum number he can finish.

Hard8Dynamic programmingGreedySimulationImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

Taro is a student at Ibaraki College of Prominent Computing. This semester he takes two courses, mathematics and informatics. After a class the teacher may assign homework. A single class can produce several assignments, and each assignment may have its own deadline. Every assignment carries a distinct ID number.

Every day after school Taro finishes at most one assignment, in the following way. He first flips a coin to decide which course to work on. Let SS be the set of all assignments of the chosen course that have already been given, are still unfinished, and whose deadline has not passed. If SS is empty, he plays a video game and does no homework that day, even when the other course still has unfinished assignments. Otherwise, let TST \subseteq S be the assignments of SS with the nearest deadline; he finishes the one with the smallest ID in TT.

The number of assignments Taro finishes by the end of the semester depends on the coin flips. Given the schedule of the assignments, compute the maximum and the minimum number of assignments Taro finishes. The semester runs from day 1 to day 400, and Taro flips the coin on every one of those days.

Input

The input consists of a single test case in the following format.

n m
s1 t1
.
.
.
sn tn

The first line contains two integers nn and mm with 1m<n4001 \le m < n \le 400. Here nn is the total number of assignments in this semester and mm is the number of assignments of the mathematics course, so the informatics course has nmn - m assignments. Assignment IDs run from 1 to nn: IDs 1 through mm belong to mathematics, and the rest belong to informatics. The next nn lines give the schedule of the assignments. The ii-th of them contains two integers sis_i and tit_i with 1siti4001 \le s_i \le t_i \le 400. Assignment ii is given to Taro on day sis_i of the semester, and its deadline is the end of day tit_i.

Output

In the first line, print the maximum number of assignments Taro finishes. In the second line, print the minimum number.