1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <bits/stdc++.h>

#define endl '\n'
#define LL long long
#define fi first
#define sc second
using namespace std;

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
	int N, M;
	cin >> N >> M;
	vector<int> Tab(N);
	for(auto& x : Tab){
		cin >> x;
	}
	sort(Tab.rbegin(), Tab.rend());
	//for(auto x : Tab) cout << x << " ";
	int i = M-1;
	while(i < N && Tab[i] == Tab[M - 1]){
		i++;
	}
	cout << i << endl;
	return 0;
}