N,A = map(int,input().split()) S = input() Zcnt, Ocnt = S.count("0"), S.count("1") rate = 1200 Ans = 0 nowAC = 0 if Zcnt > Ocnt: ACcnt = 0 while ACcnt != Ocnt and nowAC + Ocnt < A: ACcnt = 0 for s in S: if s == "0": rate -= 1 elif rate <= 1199: ACcnt += 1 rate += 1 nowAC += 1 Ans += N if nowAC + Ocnt >= A: while nowAC < A: for s in S: if s == "0": rate -= 1 elif rate <= 1199: rate += 1 nowAC += 1 Ans += 1 if nowAC == A: break else: roop = (A - nowAC - 1) // Ocnt nowAC += roop*Ocnt Ans += roop*N for s in S: Ans += 1 if s == "1": nowAC += 1 if nowAC == A: break print(Ans) else: rateLog = [1200] ACLog = [] ROOP = False while not ROOP and nowAC + Ocnt < A: ACcnt = 0 for s in S: if s == "0": rate -= 1 elif rate <= 1199: rate += 1 nowAC += 1 ACcnt += 1 Ans += N ACLog.append(ACcnt) if rate in rateLog: ROOP = True else: rateLog.append(rate) if nowAC + Ocnt >= A: while nowAC < A: for s in S: if s == "0": rate -= 1 elif rate <= 1199: rate += 1 nowAC += 1 Ans += 1 if nowAC == A: break else: roop_start = rateLog.index(rate) roop_length = len(ACLog) - roop_start roop_AC = sum(ACLog[roop_start:]) roop = (A - nowAC - 1) // roop_AC nowAC += roop*roop_AC Ans += roop*roop_length*N while nowAC < A: for s in S: if s == "0": rate -= 1 elif rate <= 1199: rate += 1 nowAC += 1 Ans += 1 if nowAC == A: break print(Ans)