#include #include using namespace std; int n, k, i, j; int main(){ cin >> n >> k; int p, q; int a[n]; int ans = 0; int tmp = 0, tmpa = 0, tmpb = 0; for(i = 0; i < n; i++){cin >> a[i];} if(a[k - 1] == 0){ cout << 0 << endl; return 0; } p = 0, q = n - 1; for(i = 0; i < n; i++){ if(i < k - 1 && (a[i] == 1 || a[i] == 0)){ p = i; }else if(i > k - 1 && (a[i] == 1 || a[i] == 0)){ q = i; break; } } if(a[k - 1] == 1){ for(i = p; i <= q; i++){ if(i < k - 1) tmpa += a[i]; if(i > k - 1) tmpb += a[i]; } ans = max(tmpa, tmpb) + 1; }else{ for(i = p; i <= q; i++){ ans += a[i]; } } cout << ans << endl; return 0; }