#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) {
        cout << 2 << endl;
    }
    else
    {
        if(cnt1 + cnt2 >= k) 
        {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    }
    return 0;
}
