#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 1e6 + 5;
int arr[MAXN];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    int br1 = 0, br2 = 0, br12 = 0;
    for(int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        if(arr[i] == 1) br1++;
        else if(arr[i] == 2) br2++;
    }
    bool flag1 = false, flag2 = false;
    for(int i = 1; i <= n; i++)
    {
        if(arr[i] == 1)
        {
            flag1 = true;
        }
        else if(arr[i] == 2)
        {
            flag2 = true;
        }
        if(flag1 && flag2)
        {
            br12++;
            flag1 = false;
            flag2 = false;
        }
    }
    if(br12 >= k) cout << 3 << endl;
    else if(br2 >= k) cout << 2 << endl;
    else if(br1 >= k) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}
