cswork / OAOpen practice workspace

HackerearthOA #1

Happy Neighbourhood

Estimated MediumJudge-ready

Topics (AI-labelled)Union-FindIn-place Arrays

Houses are numbered 1..N, and people move in one house at a time in the order of the given permutation. Find the earliest day on which some contiguous segment of M houses is fully occupied.

Input

The input contains N, M and a permutation of length N. 1≤N≤100000, 1≤M≤N.

Output

Output the day on which a fully occupied contiguous segment of length M first appears.

Example 1

Input:

3
1
3 2 1

Output:

1

Example 2

Input:

10
8
8 4 9 10 3 1 7 2 6 5

Output:

10

Example 3

Input:

20
2
16 12 14 7 11 13 15 4 1 20 9 3 10 8 6 2 17 19 18 5

Output:

5

Editorial

Loading solution…