The Boneli test P47121


Statement
 

pdf   zip

ifnextchar ( ifnextchar (offsettrue(0pt,0pt) offsetfalse ifnextchar [(0pt,0pt)(0pt,0pt) ifnextchar [(0pt,0pt)(0pt,0pt)[l](0pt,0pt)(0pt,0pt)[l][] [r]

Apart from the Voight-Kampff test, there is a simpler way to identify repicants: the Boneli test. (It measures the speed of the reflex-arc response which takes place in the upper ganglia of the spinal column. Much simpler, indeed…) Since Rick Deckard is falling in love with Rachael, he will use the Boneli test as an excuse to try to seduce her (it). Cunning Rick has told Rachael that, to apply the test, he must measure the blood pressure near her (its) heart!

Rick already took nn measures (and yes, he seduced Rachael), but now he wonders if those measures may have some interest. For every subsequence of cc consecutive measures, Rick only takes into account its maximum value. Rick wants to know, among the maximums of all those subsequences (overlapping or not), which is the minimum value mm.

For instance, if c=3c = 3, n=5n = 5, and the sequence is 7 4 2 6 8, we have three subsequences: 7 4 2, 4 2 6, and 2 6 8. Therefore, m=6m = 6 for this example, corresponding to the middle subsequence.

Input

Input consists of several cases, each with cc and nn, followed by nn natural numbers. Assume 1cn1061 \le c \le n \le 10^6. A case with c=n=0c = n = 0 ends the input.

Output

For every case, print its corresponding mm.

Public test cases
  • Input

    3 5
    7 4 2 6 8
    
    1 1
    500000000
    
    1 2
    1 3
    
    2 2
    1 3
    
    2 5
    0 0 0 0 0
    
    0 0
    

    Output

    6
    500000000
    1
    3
    0
    
  • Information
    Author
    Marçal Garolera
    Language
    English
    Official solutions
    C++
    User solutions
    C++