Breed Proximity

No attempts yetTime limit1sMemory limit128 MB

Problem

Farmer John's $N$ cows ($1 \le N \le 50000$) are standing in a line, each described by an integer breed id.

Cows of the same breed are at risk of getting into an argument with each other if they are standing too close. Specifically, two cows of the same breed are said to be "crowded" if their positions within the line differ by no more than $K$ ($1 \le K < N$).

Compute the maximum breed id over all pairs of crowded cows.

Input

  • Line 1: Two space-separated integers, $N$ and $K$.
  • Lines 2..$N+1$: Each line contains the breed id of a single cow in the line. All breed ids are integers in the range $0$ to $1000000$.

Output

  • Line 1: The maximum breed id of a crowded pair of cows, or $-1$ if there is no crowded pair.

Hint

There are 6 cows in a line with breed ids $7, 3, 4, 2, 3, 4$ and $K = 3$. Two cows of the same breed are crowded if their positions differ by at most $3$. The two cows of breed id $3$ (positions $2$ and $5$, difference $3$) are crowded, and so are the two cows of breed id $4$ (positions $3$ and $6$, difference $3$). Hence the answer is $4$.