N,K=map(int,input().split()) S=input() h=[0]*(N+1) x=0 E=[0]*(N+1) for i in range(N): if S[i]=='1': x+=1 E[i+1]=E[i]+1 else: x-=1 E[i+1]=E[i] h[i+1]=max(h[i],x) P=x t=max(h) l=1 r=2*10**18 z=E[N] while True: if l==r: break m=(l+r)//2 count=m//N pos=m%N d=max(count*x+h[pos],h[pos]) if count>0: d=max(d,(count-1)*x+t,t) score=z*count+E[pos]-d if score>=K: r=m else: l=m+1 print(l)