Matching Bins

Time limit1sMemory limit128 MB

Problem

A factory depot has a long row of empty bins standing side by side. The depot manager wants to free up space on the left end of the row by nesting some bins inside others.

A robot moves bins with exactly one kind of operation: it picks up a bin, carries it to the right, and places it inside a strictly larger bin. Safety rules allow a bin to hold at most one other bin, and that inner bin must itself be empty.

The manager wants every resulting nested (double) bin to end up at the left end of the row. Concretely, look at the $K$ leftmost bins together with the $K$ bins immediately to their right. Find the largest $K$ for which each of those $K$ leftmost bins can be placed inside a distinct bin among the next $K$ bins (in some order), where every bin is placed inside a strictly larger one. Note that $K = 0$ is always valid and $2K$ may not exceed $N$.

Input

The first line contains two integers $M$ and $N$ ($1 \le M \le 1000$, $1 \le N \le 20000$): the size of the largest bin and the number of bins.

The second line contains $N$ integers $A_1, A_2, \dots, A_N$ ($1 \le A_i \le M$): the bin sizes listed from left to right.

Output

Print a single integer: the largest $K$ such that the $K$ leftmost bins can each be placed inside a distinct, strictly larger bin among the next $K$ bins.