Under construction

Still being built. Things may change

Apartment

Interview

Time limit1sMemory limit1024 MB

Summary
Given N and M participants with two hand heights each, find which participant drinks after the lowest hand is moved to the top N times.
Level

Easy3 of 10

Topics
Sorting, Simulation
Solved
No attempts yet

Problem

Busan National University's Division of Computer Science and Engineering goes on a spring MT every year. Sanjini, a freshman who went on the spring MT, learned a drinking game called Apartment.

  1. The person who starts the game chooses the floor number NN of the apartment.
  2. Every participant stretches out both hands at heights that differ from everyone else's, so that all the participants' hands are stacked on top of each other.
  3. Take the lowest hand and place it on top of the stack.
  4. Repeat step 3 NN times. The hand stacked jj-th becomes floor jj.
  5. The participant who stacks floor NN drinks, and the game ends.

Sanjini wonders who will have to drink. Find out who will drink for Sanjini.

Input

The first line contains the floor number NN and the number of participants MM, separated by a space. (1≤N,M≤1 0001 \leq N, M \leq 1\,000)

From the second line through line M+1M+1, the heights of the two hands H1,iH_{1,i} and H2,iH_{2,i} of participant ii are given, separated by a space. (1≤H1,i,H2,i≤10 0001 \leq H_{1,i}, H_{2,i} \leq 10\,000)

No two hands have the same height. All input values are integers.

Output

Print the number of the participant who will drink.

Examples1

  1. Example 1

    Input
    5 3
    1 6
    3 4
    2 5
    
    Expected output
    3