#include<bits/stdc++.h>
using namespace std;
#define N 1000009
int n , k;
vector<int> v;
int mx = 0;
int a[N];

void solve(){
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    // check 3;
    int sum = 0 , idx = -1;
    for(int i = 1; i <= n; i++){
        sum |= a[i];   
        if(sum == 3){
            idx = i;
            break;
        }     
    }
    if(~idx){
        int co = 0;
        for(int i = idx + 1; i <= n; i++){
            co += (a[i] == 1);
        }
        if(co >= k - 1){
            cout << 3 << endl;
            return;
        }
    }
    cout << 2 << endl;
}

int main(){
    solve();
}