#include<bits/stdc++.h>
using namespace std;
int main(){
/*
axe = a[k-1]
iza el axe akbar min x = tmam
iza ado = ++counter
iza ashar meno 3ady
*/
int n, k, counter = 0, axe, s;
cin >> n>> k;
vector<int> v;
for(int i =0; i < n; i++){
cin >> s;
v.push_back(s);
}
axe = v[k-1];
sort(v.begin(), v.end());
for(int i = k-2; i >=1; i--){
if(axe == v[i])
counter++;
else if(v[i-1] == v[i] && axe - counter <= v[i])
counter++;
//cout << axe << " " << counter << endl;
}
cout << axe + counter;
}