#include <bits/stdc++.h> using namespace std; #define REP(i,first,last) for (int i=first;i<last;++i) #define MAX(x,y) (x > y ? x : y) #define MIN(x,y) (x < y ? x : y) int N, K; int main(){ cin >> N >> K; vector<char> ice_box(N); REP(i,0,N){ cin >> ice_box[i]; } queue<int> que; int buy = 0; int eat = 0; int idx = 0; while (eat < K) { if (que.empty()) { switch (ice_box[idx]) { case '0': idx += 1; break; case '1': que.push(ice_box[(idx + 1) % N]); idx += 2; break; case '2': que.push(ice_box[(idx + 1) % N]); que.push(ice_box[(idx + 2) % N]); idx += 3; } ++buy; } else { char ice = que.front(); que.pop(); switch (ice) { case '0': break; case '1': que.push(ice_box[idx]); idx += 1; break; case '2': que.push(ice_box[idx]); que.push(ice_box[(idx + 1) % N]); idx += 2; } } idx %= N; ++eat; } cout << buy << endl; }