#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define range(a) a.begin(), a.end() int main() { int N, K; cin >> N >> K; K--; vector A(N); rep(i, N) cin >> A[i]; int l = K - 1; int r = K + 1; while (l >= 1 && A[l] >= 2) l--; while (r <= N - 2 && A[r] >= 2) r++; ll sl = 0; for (int i = max(0, l); i <= K - 1; i++) { sl += A[i]; } ll sr = 0; for (int i = min(N - 1, K + 1); i <= r; i++) { sr += A[i]; } if (A[K] == 0) { cout << 0 << endl; return 0; } if (A[K] <= 2) { cout << max(sl, sr) + A[K] << endl; } else { cout << sl + sr + A[K] << endl; } }