#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define INPUT "sdo.in"
#define OUTPUT "sdo.out"
#define MAX 3000004
#define SUCCESS 0
#define BOGUS_VALUE 0
int choosePivot(int left, int right) {
return left + rand() % (right - left + 1);
}
void swap(int a[], int i, int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
int partition(int a[], int left, int right) {
int pivotIndex = choosePivot(left, right);
int pivotValue = a[pivotIndex];
int storeIndex = left, i;
swap(a, pivotIndex, right);
for (i = left; i <= right; i++) {
if (a[i] < pivotValue) {
swap(a, storeIndex, i);
storeIndex++;
}
}
swap(a, storeIndex, right);
return storeIndex;
}
int kth(int a[], int left, int right, int position) {
if (left == right) {
if (left == position) {
return a[left];
} else {
return BOGUS_VALUE;
}
}
if (left > right) {
return BOGUS_VALUE;
}
int pivot = partition(a, left, right);
if (pivot == position) {
return a[pivot];
} else {
int found = kth(a, left, pivot - 1, position);
if (found == BOGUS_VALUE) {
return kth(a, pivot + 1, right, position);
} else {
return found;
}
}
}
int kthElement(int a[], int n, int position) {
return kth(a, 0, n - 1, position);
}
int n, k, a[MAX], i;
int main() {
freopen(INPUT, "r", stdin);
freopen(OUTPUT, "w", stdout);
srand(time(NULL));
scanf("%d %d\n", &n, &k);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
printf("%d\n", kthElement(a, n, k - 1));
fclose(stdin);
fclose(stdout);
return SUCCESS;
}