#include <bits/stdc++.h>
#define int long long
using namespace std;

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

    int n, k;
    cin >> n >> k;

    vector<int> v(n);
    for(int &num : v)cin >> num;

    int ranges = 0;
    bool seen1 = false, seen2 = false;

    for(int i=0; i<n; i++)
    {
        if(v[i] == 1)seen1 = true;
        if(v[i] == 2)seen2 = true;

        if(seen1 && seen2)
        {
            seen1 = false;
            seen2 = false;
            ranges++;
        }
    }

    if(ranges >= k){cout << 2; return 0;}

    int countOne = 0;
    for(int &num : v)if(num)countOne++;

    if(countOne < k){cout << 0; return 0;}
    cout << 1;
}
