#include <bits/stdc++.h>

using namespace std;
int v[1000005], freq[105];
int main()
{
    int n, k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>v[i];
        freq[v[i]]++;
    }
    if(k>=freq[1]+freq[2])
        cout<<0;
    else
        if(freq[2]>k)
            cout<<2;
        else
            cout<<1;
    return 0;
}
