#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, a; string s; cin >> n >> a >> s; vector ac(21), rt(21); ll rtg = 0, cor = 0; for(int j = 0; j < 20; j++){ for(int i = 0; i < n; i++){ if(s[i] == '1'){ if(rtg < 0) cor++, rtg++; if(cor == a){ cout << j * n + i + 1 << '\n'; return 0; } }else{ rtg--; } } ac[j + 1] = cor; rt[j + 1] = rtg; } assert(ac[20] - ac[19] == ac[19] - ac[18]); assert(rt[20] - rt[19] == rt[19] - rt[18]); ll d = (a - ac[20] - 1) / (ac[20] - ac[19]); rtg += d * (rt[20] - rt[19]); cor += d * (ac[20] - ac[19]); d += 20; for(int i = 0; i < s.size(); i++){ if(s[i] == '1'){ if(rtg < 0) cor++, rtg++; if(cor == a){ cout << d * n + i + 1 << '\n'; return 0; } }else{ rtg--; } } cerr << "enter" << '\n'; }