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
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;

#define fo(i, n) for(int i=0; i<n; i++)
#define FO(i, k, n) for(int i=k;i<n;i++)
#define chck(x) cout<<#x<<" "<<x<<"\n";
template<typename... T>
void read(T&... args){
    ((cin >> args), ...);
}


int main(){

    int n, k;
    cin >> n >> k;

    int in[n], stk[n];

    fo(i, n)
        cin >> in[i];

    sort(in, in+n, greater<int>());
    
    stk[n-1] = 0;
    for(int i = n-2; i >= 0; --i){
        if(in[i] == in[i+1])
            stk[i] = stk[i+1] + 1;
        else 
            stk[i] = 0;
    }

    //fo(i, n)
    //    cout << stk[i] << " ";
    //cout << "\n";

    cout << k + stk[k-1];

}