#include using namespace std; int main(){ int n,k; cin >> n >> k; long a[n+2]; a[0] = 0; for(int i=1;i<=n;i++)cin >> a[i]; a[n+1] = 0; long ans = 0; int usi = k; while(a[usi-1]>0)usi--; while(usi0)usi++; while(usi>=k){ ans+= a[usi]; usi--; } printf("%ld\n",ans); }