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

#define ll long long
#define pb push_back
#define ff first
#define sc second
#define pii pair<int, int>

const int maxN = 1e6 + 25;
const int inf = 1e9;
const ll big_inf = 1e18;
const int mod = 1e9 + 7;

int a[maxN];
int n, k;
int ans;

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

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

    int t = 1;
    // cin >> t;
    while(t--) {
        solve();
        cout << '\n';
    }
}