#include<bits/stdc++.h>
using namespace std;
int main() {
	int n , k;
	cin >> n >> k;
	int a[n];
	int cnt1 = 0, cnt2 = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		if(a[i]==2) cnt2++;
		else if(a[i]==1)cnt1++;
	}
	int ok = 0;
	bool t1 = 0, t2 = 0;
	for(int i = 0; i < n; i++){
		if(a[i]==1) t1=1;
		else if(a[i]==2) t2 = 1; 
		if(t1&&t2) {
			ok++;
			t1 = 0;
			t2 = 0;
		}
	}
	if(ok>=k) cout << 3;
	else if(cnt2>=k&&cnt1>=k) cout << 2;
	else if(cnt1>=k) cout << 1;
	else if(cnt2>=k) cout << 2;
	else cout << 0;
}
