#include #include using namespace std; using namespace atcoder; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll inf=14449999999994; ll mod=1000000007; int main(){ ll n,k; cin >> n >> k; vectora(n); for (ll i = 0; i < n; i++) { cin >> a[i]; } k--; ll x=0,y=0; for (ll i = k+1; i < n; i++) { if (a[i]<=1) { x+=a[i]; break; } x+=a[i]; } for (ll i = k-1; i >=0; i--) { if (a[i]<=1) { y+=a[i]; break; } y+=a[i]; } if (a[k]>=2) { cout << x+y+a[k] << endl; }else if (a[k]==1) { cout << max(x,y)+1 << endl; }else{ cout << 0 << endl; } }