#include using namespace std; using ll = long long; using P = pair; constexpr ll INF = 9e18; constexpr int inf = 1e9; constexpr double INFD = 1e100; constexpr ll mod = 1000000007; const double PI = 3.1415926535897932384626433832795028841971; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } // --------------------------------------------------------------------------- int main(){ int N,K; cin >> N >> K; K--; vector A(N); for(int i=0; i> A[i]; } if(A[K] == 0){ cout << 0 << endl; return 0; } ll sum_l=0; for(int i=K+1; i=0; i--){ sum_r += A[i]; if(A[i] < 2){ break; } } if(A[K] == 1){ cout << max(sum_l,sum_r) + 1 << endl; }else{ cout << sum_l + sum_r + A[K] << endl; } return 0; }