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
40
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, n) for (int i = 0; i < int(n); ++i)
#define FO(i, a, b) for (int i = (a); i < int(b); ++i)
#define OF(i, a, b) for (int i = (b)-1; i >= int(a); --i)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((b) < (a) ? (a) : (b))

#define REMIN(a, b) ((a) = min(a, b))
#define REMAX(a, b) ((a) = max(a, b))

#define ALL(c) (c).begin(), (c).end()

#define SQR(x) ((x) * (x))

//

int main() {
  ios_base::sync_with_stdio(0);

  int n, k;

  cin >> n >> k;

  vector<int> arr(n);

  FOR(i, n) { cin >> arr[i]; }

  sort(ALL(arr), [](auto& a, auto& b) { return a > b; });

  int r = k;

  while (r < n && arr[r - 1] == arr[r]) ++r;

  cout << r << endl;

  return 0;
}