#include <iostream>
#include <vector>
using namespace std;
int n, k;
long long ans = 0, now = 1;
int a[1000005];

/*void rec(int cnt, int start) {
	long long res = 0, nowres = now;
	if (now == 0) { return; }
	if (cnt == k-1) {
		for (int i = start; i < n - k + cnt + 1; i++) {
			res = res | a[i];
		}
		now = now & res;
		ans = max(ans, now);
		now = nowres;
		return;
	}
	if (cnt == 0) {
		for (int i = start; i < n - k + cnt + 1; i++) {
			res = res | a[i];
			now = res;
			rec(cnt + 1, i + 1);
		}
		return;
	}
	for (int i = start; i < n - k + cnt + 1; i++) {
		res = res | a[i];
		now = now & res;
		rec(cnt + 1, i + 1);
		now = nowres;
	}
	return;
}*/
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> k;
	long long one = 0,two=0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 1) {
			one++;
		}
		else if (a[i] == 2) {
			two++;
		}
	}
	if (one >= k) {
		if (two >= k) {
			cout << 3;
		}
		else {
			cout << 1;
		}
	}
	else if (two >= k) {
		cout << 2;
	}
	else {
		cout << 0;
	}
	//rec(0,0);
	//cout << ans;
}