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
/*
    Piotr Bieńkowski
    bbienkos@gmail.com
    Akademickie Liceum Ogólnokształcące Politechniki Wrocławskiej
*/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int, int>
#define debug(x); cerr << #x << " = " << x << "\n";
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

const int N = 2e3 + 7;
const int INF = 1e9 + 9;

int tab[N];
int n, k;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    tab[0] = -INF;
    for(int i = 1; i <= n; i++)
    {
        cin >> tab[i];
        tab[i] *= -1;
    }
    sort(tab, tab + n + 1);
    while(k <= n && tab[k] == tab[k + 1]) k++;
    cout << k << "\n";
}