This page is still under construction.

Parts of this page are still being built. What you see may change.

Knigs of the Forest

Time limit1sMemory limit128 MB

Summary
Given the strengths and entry years of all competing moose, find the year Karl-Algtav becomes champion, or report unknown.
Level

Medium7 of 10

Topics
Heap, Simulation, Greedy, Sorting
Solved
No attempts yet

Problem

All moose are kings of the forest, but your latest moose-friend, Karl-Älgtav, is more interesting than most — in part because of his fondness for fermented blueberries, and in part because of the tribe he lives in.

Each year his tribe holds a tournament to decide that year's alpha-moose. The winner mates with all the moose-chicks and then permanently leaves the tribe. The pool of contenders keeps the same size every year: the departing alpha-moose is replaced by exactly one newcomer before the next tournament.

Karl-Älgtav wants to know when it will finally be his turn to win all the chicks. He has given you the strength and the year of entry of every other male moose in his tribe that will compete over the coming n−1n-1 years. Assuming that the moose with the greatest strength wins each year's tournament, determine the year in which Karl-Älgtav becomes the alpha-moose.

Input

The first line contains two space-separated integers kk (1≤k≤1051 \le k \le 10^5) and nn (1≤n≤1051 \le n \le 10^5): the size of the tournament pool and the number of years for which you have enough information.

The next line describes Karl-Älgtav with two integers yy (2011≤y≤2011+n−12011 \le y \le 2011 + n - 1) and pp (0≤p≤231−10 \le p \le 2^{31} - 1): his year of entry into the tournament and his strength.

Each of the following n+k−2n + k - 2 lines describes one of the other moose in the same format, giving its year of entry and its strength.

Exactly kk of the moose have 20112011 as their year of entry, and the remaining n−1n - 1 moose each have a distinct year of entry. Every moose has a distinct strength.

Output

Output the year in which Karl-Älgtav wins the tournament, or unknown if the given data is not enough to determine it.

Examples2

  1. Example 1

    Input
    2 4
    2013 2
    2011 1
    2011 3
    2014 4
    2012 6
    
    Expected output
    2013
    
  2. Example 2

    Input
    2 4
    2011 1
    2013 2
    2012 4
    2011 5
    2014 3
    
    Expected output
    unknown