#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    int col_1 = 0;
    int col_2 = 0;
    bool z = 0;
    int r = 0;
    vector <int> v;
    int col_b = 0;
    for (int i = 0; i < n; i++) {
         cin >> a[i];
         if (a[i] == 1) {
             z = 1;
             col_1++;
         } else {
           if (z == 1) {
               col_b++;
           }
           z = 0;
           col_2++;
         }
    }
    if (col_1 == n) {
        cout << 1 << "\n";
        return 0;
    }
    if (z == 1) {
        col_b++;
    }
    int ot = col_b * 2;
    if (a[0] == 1) {
        ot--;
    }
    if (a[n - 1] == 1) {
        ot--;
    }
    r = ot;
    bool x = 0;
    if (col_2 >= k + 1) {
        if (col_2 - r >= k + 1) {
            cout << 3 << "\n";
            return 0;
        } else {
          cout << 2 << "\n";
          return 0;
        }
    }
    cout << 1 << "\n";
    return 0;
}
