#include int main() { int n, k; scanf("%d %d", &n, &k); int i; long long int a[200005]; for (i = 0; i < n; i++) scanf("%lld", &a[i]); long long int ans[2]; k--; if (a[k] == 0) { printf("0\n"); return 0; } ans[0] = 0; for (i = k - 1; i >= 0; i--) { ans[0] += a[i]; if (a[i] < 2) break; } ans[1] = 0; for (i = k + 1; i < n; i++) { ans[1] += a[i]; if (a[i] < 2) break; } if (a[k] == 1) { if (ans[0] > ans[1]) printf("%lld\n", ans[0] + 1); else printf("%lld\n", ans[1] + 1); } else printf("%lld\n", ans[0] + ans[1] + a[k]); return 0; }