Roll Cake

Time limit1sMemory limit128 MB

Summary
Given N interval requests over pieces 1..L, find the member with the largest requested length, then the member who actually receives the most pieces when earlier requests get priority.
Level

Easy3 of 10

Topics
Simulation, Array, Implementation
Solved
No attempts yet

Problem

A roll cake LL meters long is to be shared among NN audience members.

The cake is cut into 11-meter pieces. The leftmost piece is numbered 11 and the rightmost piece is numbered LL. The audience members are numbered from 11 to NN.

Each audience member ii writes two integers PiP_i and KiK_i on a slip of paper, meaning they want pieces PiP_i through KiK_i.

The host reads the slips in order, starting with member 11. When reading member ii's slip, for each piece from PiP_i to KiK_i that has not yet been assigned to anyone, the host marks it with ii's number and gives it to that member. Any piece already marked with another member's number is skipped. As a result, a member may not receive all of the pieces they asked for.

The figure below illustrates how the pieces are handed out.

The number of pieces member ii expects to receive equals the number of pieces they wrote down, that is Ki−Pi+1K_i - P_i + 1. Write a program that finds the number of the member who expected to receive the most pieces, and the number of the member who actually received the most pieces.

Input

The first line contains the length of the roll cake LL (1≤L≤10001 \le L \le 1000).

The second line contains the number of audience members NN (1≤N≤10001 \le N \le 1000).

Each of the next NN lines contains the two integers PiP_i and KiK_i written by member ii (1≤Pi≤Ki≤L1 \le P_i \le K_i \le L).

Output

On the first line, print the number of the member who expected to receive the most pieces.

On the second line, print the number of the member who actually received the most pieces.

In both cases, if more than one member satisfies the condition, print the smallest such member number.

Examples3

  1. Example 1

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

    Input
    10
    3
    1 3
    5 7
    8 9
    
    Expected output
    1
    1
    
  3. Example 3

    Input
    10
    5
    1 1
    1 2
    1 3
    1 4
    7 8
    
    Expected output
    4
    5