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
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
#include <bits/stdc++.h>
#include <iostream>

//#define TEST

using namespace std;

#define FAST  ios_base::sync_with_stdio(0) ;cin.tie(0);

#define pb push_back
#define mp make_pair

#define fi(a, b) for(int i=a; i<=b; i++)
#define fj(a, b) for(int j=a; j<=b; j++)
#define fo(a, b) for(int o=a; o<=b; o++)

#define fdi(a, b) for(int i=a; i>=b; i--)
#define fdj(a, b) for(int j=a; j>=b; j--)
#define fdo(a, b) for(int o=a; o>=b; o--)

#define sz(x) (int)x.size()

#define init_v( tab, n ) fo(1, n ) tab.pb(0)

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <pii> vpii;
typedef pair <ll, ll> pll;
typedef vector <pll> vpll;
typedef vector <ll> vll;

template <typename T> ostream& operator<<( ostream& os, vector<T> v)
{
    fi(0, sz(v) - 1)   os << v[i] << " ";
    return os;
}
template <typename A, typename B> ostream& operator <<(ostream& os, pair< A, B> p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream& operator<<( ostream& os, set<T> t)
{
    for (auto z : t)
    {
        os << z << " ";
    }
    return os;
}
template <typename T1, typename T2> ostream& operator <<(ostream& os, map< T1, T2> t)
{
    cerr << endl;
    for (auto z : t)
    {
        os << "\t" << z.first << " -> " << z.second << endl;
    }
    return os;
}

#ifdef TEST
#define dbg(x) {cerr << __LINE__ << "\t" << #x << ": " << x << endl;}
#define dbg0(x, n) {cerr << __LINE__ << "\t" << #x << ": "; for (int ABC = 0; ABC < n; ABC++) cerr << x[ABC] << ' '; cerr << endl;}
#else
#define dbg(x) ;
#define dbg0(x, n) ;
#endif

void przekierowanie()
{
#ifdef TEST
    freopen( "input.txt", "r", stdin );
    freopen( "output.txt", "w", stdout );
#endif
}

int main()
{
    FAST
    przekierowanie();
    ll N, K;
    cin >> N >> K;
    auto x = N;
    vll tab;
    while ( x --)
    {
        ll pom;
        cin >> pom;
        tab.pb( pom );
    }
    sort( tab.begin(), tab.end(), [](ll a, ll b){ return b < a;});
 //   for( auto x: tab )
 //      cout << x << " ";cout << endl;
    auto p1 = tab[ K - 1];
    auto t1 = K - 1;
    ll delta = 0;
    while( t1 + delta < N && p1 == tab[ t1 + delta ] )
        delta ++;
    cout << t1 + delta << '\n';
    return 0;
}