# frozen_string_literal: true N, K = gets.chomp.split.map(&:to_i) AS = gets.chomp.split.map(&:to_i) if AS[K - 1].zero? puts(0) exit end count = 0 [AS[K..-1], AS[0..K - 1].reverse].each do |a| a.take_while do |i| if i >= 2 count += i true elsif i == 1 count += 1 false else false end end end puts count