#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int MAX_N = 1e6;
int n, k, a[MAX_N];
int ans;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> k;
    int cnt1 = 0, cnt2 = 0;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        cnt1 += (a[i] == 1);
        cnt2 += (a[i] == 2);
    }

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

    int cntgroups = 0;
    int i = 0;
    while(i < n) {
        int j = i;
        bool has1 = false, has2 = false;
        while(j < n && !has1 && !has2) {
            if(a[j] == 1) has1 = true;
            if(a[j] == 2) has2 = true;
            ++j;
        }
        if(!has1 && !has2) ++cntgroups;
        i = j+1;
    }

    if(cntgroups >= k)
    {
        cout << 3 << endl;
    }
    else
    {
        cout << 2 << endl;
    }

    return 0;
}
