#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; typedef vector VI; typedef vector VL; typedef pair PI; const ll mod = 1e9 + 7; int main(void){ int n; ll k; cin >> n >> k; string s; cin >> s; int tot = 0; REP(i, 0, n) { tot += s[i] - '0'; } if (tot >= n) { int acc = 0; int last = 0; REP(i, 0, n) { if (i + 1 > acc) { last = max(last, i + 1 - acc); } acc += s[i] - '0'; } cout << last << endl; return 0; } int r = k % n; ll acc = k - k / n * tot; VI te(2 * n); int cur = 0; int cnt = 0; REP(i, 0, 2 * n) { if (cur >= 1) { cur--; cnt++; } cur += s[i % n] - '0'; te[i] = cur; } //acc -= cnt; cout << (k >= n ? acc - te[n + r - 2] + tot : k - (k >= 2 ? te[k - 2] : 0)) << endl; }