#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair <ll, ll>
#define ret return
#define pb push_back
#define all(x) x.begin(), x.end()
#define fr first
#define sc second

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    int n, k, c = 0, d = 0, ans = 0, c1 = 0, d1 = 0;
    bool tst2 = true;
    cin >> n >> k;
    vector <int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        if(a[i] > 2) tst2 = false;
        if(a[i] == 1) {
            c++;
            c1++;
        }
        if(a[i] == 2) {
            d++;
            d1++;
        }
        if(d > 0 && c > 0) {
            d = 0;
            c = 0;
            ans++;
        }
    }
    if(tst2) {
        if(ans >= k) cout << 3;
        else {
            if(d1 >= k) cout << 2;
            else if(c1 >= k) cout << 1;
            else cout << 0;
        }
    }
}
