#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;

void solve () {
    ll n, k; cin >> n >> k;

    vector<ll> v(n);
    for (ll& x : v) cin >> x;


    ll cnt1 = count(v.begin(), v.end(), 1), cnt0 = count(v.begin(), v.end(), 0);

    if (cnt1 + cnt0 == n) {
        if (cnt1 >= k) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
        return;
    }

    ll cnt2 = count(v.begin(), v.end(), 2);

    ll cnt = 0;

    bool st = false;
    for (ll i = 0; i < n; ++i) {
        if (v[i] == 1) {
            st = true;
        }

        if (st && v[i] == 2) {
            st = false;
            cnt++;
        }
    }

    if (cnt >= k) {
        cout << 3 << endl; return;
    }

    if (cnt2 >= k) {
        cout << 2 << endl; return;
    }

    cout << 0 << endl;


}

signed main () {
    ll t = 1; //cin >> t;

    for (ll cs = 1; cs <= t; ++cs) {
        // cout << "Case " << cs << ": " << endl;
        solve ();
    }
}   