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

const int maxn = 1e6 + 1;
int nc[maxn];

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k, r = -1, hval = 0, br1 = 0, br2 = 0, ans;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        cin >> nc[i];
        if(nc[i] == 1) br1++;
        if(nc[i] == 2) br2++;
    }
    if(br1 >= k && br2 >= k) ans = 3;
    else if(br1 + br2 >= 2 * k && br1 < k) ans = 2;
    else if((br1 + br2 >= k && br2 < k && br1 < k) || (br2 == 0 && br1 >= k)) ans = 1;
    else ans = 0;
    cout << ans;
    return 0;
}
