#include using namespace std; typedef long long ll; typedef long int li; typedef long double lb; #define rep(i,j,n) for (ll i = j; i < (n); i++) #define repr(i,j,n) for(ll i = j; i >= (n); i--) #define all(x) (x).begin(),(x).end() #define CLR(mat,f) memset(mat, f, sizeof(mat)) #define IN(a, b, x) (a<=x&&x 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; } typedef pairP; const ll mod=1e9+7; const ll INF = 1LL<<60; const ll m=1LL<<32; int main(){ ll n,k;cin>>n>>k; ll a[n];rep(i,0,n)cin>>a[i]; ll ans=0; bool e[2]; e[0]=false; ll mi[2]; repr(i,max((ll)0,k-2),0){ if(a[i]<=1){ if(!e[0])mi[0]=ans+a[i]; e[0]=true; } if(a[i]==0)break; ans+=a[i]; } e[1]=false; ll num=0; rep(i,k,n){ if(a[i]<=1){ if(!e[1])mi[1]=num+a[i]; e[1]=true; } if(a[i]==0)break; num+=a[i]; } // out(ans<<" "<