N, K = gets.split(" ").map{|s| s.to_i} a = gets.split(" ").map{|s| s.to_i} if a[K-1] == 0 then puts 0 else lsum = 0 (K-2).downto(0) {|i| lsum += a[i] break if a[i] < 2 } rsum = 0 K.upto(N-1) {|i| rsum += a[i] break if a[i] < 2 } if a[K-1] == 1 then puts [lsum, rsum].max + 1 else puts lsum + rsum + a[K-1] end end