#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 #define MOD 1000000007 //#define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 const double EPS = 1e-10; using ll = long long; using Pi = pair; using Pl = pair; int main(){ int N,K; cin >> N >> K; K--; vector a(N); rep(i,N) cin >> a[i]; if(a[K] == 0){ cout << 0 << endl; return 0; } int idx1 = N-1,idx2 = 0; repr(i,K+1,N){ if(a[i] == 1){ idx1 = i; break; } if(a[i] == 0){ idx1 = i-1; break; } } for(int i = K-1; i >= 0; i--){ if(a[i] == 1){ idx2 = i; break; } if(a[i] == 0){ idx2 = i+1; break; } } ll sum1 = a[K],sum2 = a[K]; repr(i,K+1,idx1+1){ sum1 += a[i]; } for(int i = K-1; i >= idx2; i--){ sum2 += a[i]; } if(a[K] == 1) cout << max(sum1,sum2) << endl; else cout << sum1+sum2-a[K] << endl; }