#include<bits/stdc++.h>
using namespace std;
int main(){
int k, n, s, counter = 0;
cin >> n >> k;
vector<int> v;
for(int i = 0; i < n; i++){
cin >> s;
v.push_back(s);
}
sort(v.begin(), v.end());
for(int i =0; i < n; i++){
if(v[i] == v[k-1])
counter++;
}
cout << v[k-1] + counter -1;
}