#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int n, k;
long long maxi_length = -1;
vector<long long> eagers;
bool works(long long x) {
	if (x == 3) {
		int amount = 0, current = 0;
		for (int i = 0; i < n; i++) {
			current = current | eagers[i];
			if (current == 3) {
				amount++;
				current = 0;
			}
		}
		if (amount >= k) return true;
		return false;
	}
	else{
		int amount = 0;
		for (int i = 0; i < n; i++) {
			if (eagers[i] == x) {
				amount++;
			}
		}
		if (amount >= k) {
			return true;
		}
		return false;
	}
}
int main() {
	cin >> n >> k;
	eagers.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> eagers[i];
	}
	if (works(3)) cout << 3 << "\n";
	else if (works(2)) cout << 2 << "\n";
	else if (works(1)) cout << 1 << "\n";
	else cout << 0 << "\n";
}