using static System.Math; using System; public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]) - 1; line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); int ans; if (a[k] == 0) ans = 0; else if (a[k] == 1) ans = Max(getAns(n, k, a), getAns2(n, k, a)) + 1; else ans = a[k] + getAns(n, k, a) + getAns2(n, k, a); Console.WriteLine(ans); } static int getAns(int n, int k, int[] a) { var ans = 0; var p = k + 1; while (p < n) { if (a[p] >= 2) { ans += a[p]; p++; } else if (a[p] == 1) { ans++; break; } else break; } return ans; } static int getAns2(int n, int k, int[] a) { var ans = 0; var p = k - 1; while (p >= 0) { if (a[p] >= 2) { ans += a[p]; p--; } else if (a[p] == 1) { ans++; break; } else break; } return ans; } }