#include "partition.h"
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <set>
#include <cmath>

#define ll long long
#define sz size()
#define cY cout << "YES" << endl;
#define cN cout << "NO" << endl;
#define pb push_back
#define F first
#define S second
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


/*
"0.000..."   setprecision(---) + fixed
"USACO"      freopen("---", "r", stdin); freopen("---", "w", stdout);
"Matrix"     vector <vector <int>> ---(---, vector <int> (---));
"NOD"        __gcd
"NOK"        a * b / __gcd(a,b)
*/

using namespace std;

int main() {
    FASTIO
    ll T_T = 1;
    //cin >> T_T;
    while (T_T--) {
        ll n, k;
        cin >> n >> k;

        vector <ll> a(n);
        map <ll, ll> mp;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            mp[a[i]]++;
        }

        ll pat = 0, sum = 0;
        for (ll i = k; i >= 0; i--) {
            if (sum + mp[i].S >= k) {
                pat = i;
                break;
            }
            else {
                sum += mp[i].S;
            }
        }

        if (mp[2].S >= k && mp[1] >= k) {
            pat = max(pat, 3);
        }

        cout << pat << endl;
    }
}