import java.util.*;

public class Finder {
    public static int findKth(int[] a, int n, int K) {

        return quickSort(a,0,n-1,K);
        // write code here
    }
    public static int quickSort(int[] a, int start,int end,int K){
        if(a.length > 0 && end > start ){
            int index =  patition(a, start, end,K);
            if (K -1 < index){
                quickSort(a, start, index-1,K);
                return a[K-1];
            }else if (K -1 > index) {
                quickSort(a, index + 1, end, K);
                return a[K-1];
            }else {
                return a[index];
            }

        }
        return -1;
    }
    public static int patition(int[] a, int start , int end ,int K){
        int index  = a[start];
        while (start < end) {
            while (end > start && a[end] <= index) {
                end--;
            }
            a[start] = a[end];
            while (start < end && a[start] >= index) {
                start++;
            }
            a[end] = a[start];
        }
        a[start] = index;
        return start;
    }
}