#include <bits/stdc++.h>
using namespace std;
int main() {
    ios :: sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        cnt1 += (a == 1);
        cnt2 += (a == 2);
    }
    if (cnt2 >= k && cnt1 >= k) {
        cout << 3;
    } else if (cnt2 >= k) {
        cout << 2;
    } else if (cnt1 >= k) {
        cout << 1;
    } else {
        cout << 0;
    }
}
