N,K=map(int,input().split()) S=list(map(int,list(input().strip()))) def calc(x): ANS=(x//N)*SUM[-1] if x%N>0: ANS+=SUM[(x%N)] return ANS SUM=[0] for s in S: SUM.append(SUM[-1]+s) flag=0 if SUM[-1]>=N: flag=1 DP=[0]*(N+1) for i in range(1,N+1): NOW=DP[i-1] PLUS=NOW+1 while True: k=calc(PLUS)-calc(NOW) NOW=PLUS PLUS=PLUS+k if PLUS==NOW: break if flag==1 and PLUS>i+N: break DP[i]=PLUS if DP[i]>=K: print(i) exit() if flag==1 and DP[i]>=i+N: print(i) exit() for i in range(N+1): if DP[i]>=N: ni,nx=i,DP[i] break for i in range(N+1): if DP[i]==nx%N: bi=i break #print(bi,ni,nx) rep=(K-nx)//N ANS=ni+rep*(ni-bi) rest=(K-nx)%N #print(ANS,rest) if rest==0: print(ANS) exit() NOW=bi+1 for i in range(N+1): PLUS=NOW+1 ANS+=1 while True: k=calc(PLUS)-calc(NOW) NOW=PLUS PLUS=PLUS+k if PLUS==NOW: break if flag==1 and PLUS>i+N: break #print("!",PLUS) if PLUS>=rest: print(ANS) exit() NOW=PLUS