#P1370D. Odd-Even Subsequence

    ID: 5432 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>binary searchdpdsugreedyimplementation*2000

Odd-Even Subsequence

No submission language available for this problem.

Description

Ashish has an array aa of size nn.

A subsequence of aa is defined as a sequence that can be obtained from aa by deleting some elements (possibly none), without changing the order of the remaining elements.

Consider a subsequence ss of aa. He defines the cost of ss as the minimum between:

  • The maximum among all elements at odd indices of ss.
  • The maximum among all elements at even indices of ss.

Note that the index of an element is its index in ss, rather than its index in aa. The positions are numbered from 11. So, the cost of ss is equal to min(max(s1,s3,s5,),max(s2,s4,s6,))min(max(s_1, s_3, s_5, \ldots), max(s_2, s_4, s_6, \ldots)).

For example, the cost of {7,5,6}\{7, 5, 6\} is min(max(7,6),max(5))=min(7,5)=5min( max(7, 6), max(5) ) = min(7, 5) = 5.

Help him find the minimum cost of a subsequence of size kk.

The first line contains two integers nn and kk (2kn21052 \leq k \leq n \leq 2 \cdot 10^5)  — the size of the array aa and the size of the subsequence.

The next line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \leq a_i \leq 10^9)  — the elements of the array aa.

Output a single integer  — the minimum cost of a subsequence of size kk.

Input

The first line contains two integers nn and kk (2kn21052 \leq k \leq n \leq 2 \cdot 10^5)  — the size of the array aa and the size of the subsequence.

The next line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \leq a_i \leq 10^9)  — the elements of the array aa.

Output

Output a single integer  — the minimum cost of a subsequence of size kk.

Samples

Sample Input 1

4 2
1 2 3 4

Sample Output 1

1

Sample Input 2

4 3
1 2 3 4

Sample Output 2

2

Sample Input 3

5 3
5 3 4 2 6

Sample Output 3

2

Sample Input 4

6 4
5 3 50 2 4 5

Sample Output 4

3

Note

In the first test, consider the subsequence ss = {1,3}\{1, 3\}. Here the cost is equal to min(max(1),max(3))=1min(max(1), max(3)) = 1.

In the second test, consider the subsequence ss = {1,2,4}\{1, 2, 4\}. Here the cost is equal to min(max(1,4),max(2))=2min(max(1, 4), max(2)) = 2.

In the fourth test, consider the subsequence ss = {3,50,2,4}\{3, 50, 2, 4\}. Here the cost is equal to min(max(3,2),max(50,4))=3min(max(3, 2), max(50, 4)) = 3.