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
#include <bits/stdc++.h>
#define REP(i,n) for (int _n=(n), i=0;i<_n;++i)
#define FOR(i,a,b) for (int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for (int i=(a),_b=(b);i>=_b;--i)
#define TRACE(x) std::cerr << "TRACE(" #x ")" << std::endl;
#define DEBUG(x) std::cerr << #x << " = " << (x) << std::endl;

void init_io() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
}

int main() {
  init_io();

  int n, k;
  std::cin >> n >> k;

  std::vector<int> points;
  points.reserve(n);

  REP(i, n) {
    int p; std::cin >> p;
    points.push_back(p);
  }

  std::sort(points.begin(), points.end(), std::greater<>());
  const int val = points[k-1];
  const auto it = std::upper_bound(points.begin(), points.end(), val, std::greater<>());

  const int res = it - points.begin();
  std::cout << res << '\n';
}