Seat Assignment

Assign seats left to right, each time giving the seat to the still-unseated request with the smallest right endpoint that covers it.

Medium5GreedySortingHeapInterviewNo attempts yetTime limit0.8sMemory limit32 MB

Problem

A big match is played next week. The stadium has NN seats, numbered 11 through NN. A fan who requests a ticket also states the range of seats the fan is willing to sit in. The range is given by two integers FF and LL, and the fan accepts any seat SS with FSLF \le S \le L.

The ticket office has received MM requests. Two fans cannot get the same seat. Compute the largest number of requests that can be satisfied at the same time, and print a seat assignment for that many requests.

Input

The first line contains the number of seats NN (1N1000001 \le N \le 100000) and the number of requests MM (1M10000001 \le M \le 1000000), separated by a space.

Each of the next MM lines contains one request as two integers FF and LL (1FLN1 \le F \le L \le N). Requests are numbered 11 through MM in the order they appear in the input.

Output

Print the largest number of selected requests KK on the first line.

On each of the next KK lines print one seat assignment, in increasing order of seat number. Each line holds the seat number SS and the number RR of the request that gets seat SS, separated by a space.

Several assignments reach the maximum, so only the assignment fixed by the following rule is accepted. Scan the seats from 11 to NN. For the seat SS under consideration, collect the requests that have no seat yet and satisfy FSLF \le S \le L. If there is at least one such request, give seat SS to the one with the smallest LL. If two or more of them share the same LL, give the seat to the one with the smallest request number. If there is no such request, leave seat SS empty.

This rule always reaches the largest possible number of satisfied requests.