width = gets.to_i num = gets.to_i blocks = gets.split.map &:to_i t = 0 n = 0 for b in blocks t += b if t > width break end n += 1 end p n