#K40402. Kth Smallest Element in a List

    ID: 26634 Type: Default 1000ms 256MiB

Kth Smallest Element in a List

Kth Smallest Element in a List

You are given a list of N integers and an integer K. Your task is to determine the \(K\)th smallest element in the list.

Formally, let the list be \(a_1, a_2, \dots, a_N\). After sorting the list in non-decreasing order, let the sorted list be \(b_1 \le b_2 \le \dots \le b_N\). You need to output the element \(b_K\).

Note: It is guaranteed that 1 \(\leq K \leq N\).

inputFormat

The first line of input contains two integers N and K separated by a space, where N is the number of elements in the list and K is the position of the smallest element you need to find.

The second line of input contains N space-separated integers representing the list.

outputFormat

Output a single integer which is the \(K\)th smallest element in the list.

## sample
6 3
7 10 4 20 15 1
7