require 'matrix' N, K = gets.split.map(&:to_i) S = gets.chomp def f(s, i, m) if i == s.size Vector[0, m] elsif m > 0 f(s, i + 1, m - 1 + s[i].to_i) else f(s, i + 1, s[i].to_i) + Vector[1, 0] end end a, b = f(S, 0, 0).to_a ans = if K <= N or a <= b a else a + (K / N - 1) * (a - b) + f(S[0...(K % N)], 0, b)[0] end puts ans