#P6807. [BalticOI 2010] Matching Bins (Day2)

[BalticOI 2010] Matching Bins (Day2)

Description

You are given a sequence of NN integers A1,A2,,ANA_1,A_2,\dots,A_N. Let M=max{A1,A2,AN}M=\max\{A_1,A_2,\dots A_N\}.

You need to find the largest integer KK such that, from left to right, the first KK numbers are all smaller than the next KK numbers.

Input Format

The first line contains two integers M,NM,N, representing the maximum value in the sequence and the number of elements.

The second line contains NN integers A1,A2,,ANA_1,A_2,\dots,A_N.

Output Format

Output one integer on a single line: the maximum KK.

5 10
2 2 1 4 3 2 5 4 2 3
4

Hint

For 100%100\% of the testdata, it is guaranteed that 1M2×1031\le M\le 2\times 10^3, 1N2×1041\le N\le 2\times 10^4, 1AiM1\le A_i\le M.


This problem is translated from BalticOI 2010 Day2 T1 Matching Bins

Translated by ChatGPT 5