#include using namespace std; int n, k, i, j; int main(){ cin >> n >> k; int p, q; int a[n]; int ans = 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){ if(a[i] == 0) p = i + 1; if(a[i] == 1) p = i; }else{ if(a[i] == 0) q = i - 1; if(a[i] == 1) q = i; } } for(i = p; i < q + 1; i++){ ans += a[i]; } cout << ans << endl; return 0; }