#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
ll n , s;
ll a[400005];
const ll inf = 1e16;
set<ll> S;
ll d[400005];
int main()
{
cin >> n >> s;
ll mmm = 1e14;
for(ll i=0;i<n;i++) {
cin >> a[i];
mmm = min(mmm , a[i]);
S.insert(i);
S.insert(i + n);
}
if(n == 1) {
cout << "0\n"; return 0;
}
if(n == 2) {
cout << mmm << endl; return 0;
}
for(ll i=n;i<n+n;i++) {
a[i] = a[i - n];
}
for(ll i=0;i<n+n;i++) {
if(i) d[i] = d[i-1];
d[i] += a[i];
}
ll cur = s-1;
ll ans = 0;
while(S.size() > 2) {
auto nxt = S.lower_bound(cur);
auto prv = S.lower_bound(cur + n);
nxt++;
prv--;
ll NN = 0;
NN = *nxt;
ll PP = *prv;
S.erase(S.find(cur));
S.erase(S.find(cur+n));
ll aage = 1e9;
ll piche = 1e9;
if(NN>0) aage = d[NN-1];
if(cur>0) aage -= d[cur - 1];
if(cur+n-1>0)piche = d[cur+n-1];
if(PP > 0) piche -= d[PP-1];
if(aage < piche) {
ans += aage;
ll RA = NN;
if(RA >= n) RA -= n;
cur = RA;
}else if(aage > piche){
ans += piche;
ll RB = PP;
if(RB >= n) RB -= n;
cur = RB;
}else {
ll RA = NN;
if(RA >= n) RA -= n;
ll RB = PP;
if(RB >= n) RB -= n;
if(RA < RB) {
cur = RA;
ans += aage;
}else {
cur = RB;
ans += aage;
}
}
}
cout << ans << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgcGIgcHVzaF9iYWNrCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwpsbCBuICwgczsKbGwgYVs0MDAwMDVdOwpjb25zdCBsbCBpbmYgPSAxZTE2OwpzZXQ8bGw+IFM7CmxsIGRbNDAwMDA1XTsKaW50IG1haW4oKQp7CiAgICAgICAgY2luID4+IG4gPj4gczsKICAgICAgICBsbCBtbW0gPSAxZTE0OwogICAgICAgIGZvcihsbCBpPTA7aTxuO2krKykgewogICAgICAgICAgICAgICAgY2luID4+IGFbaV07CiAgICAgICAgICAgICAgICBtbW0gPSBtaW4obW1tICwgYVtpXSk7CiAgICAgICAgICAgICAgICBTLmluc2VydChpKTsKICAgICAgICAgICAgICAgIFMuaW5zZXJ0KGkgKyBuKTsKICAgICAgICB9CiAgICAgICAgaWYobiA9PSAxKSB7CiAgICAgICAgICAgICAgICBjb3V0IDw8ICIwXG4iOyByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgaWYobiA9PSAyKSB7CiAgICAgICAgICAgICAgICBjb3V0IDw8IG1tbSA8PCBlbmRsOyByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgZm9yKGxsIGk9bjtpPG4rbjtpKyspIHsKICAgICAgICAgICAgICAgIGFbaV0gPSBhW2kgLSBuXTsKICAgICAgICB9CiAgICAgICAgZm9yKGxsIGk9MDtpPG4rbjtpKyspIHsKICAgICAgICAgICAgICAgIGlmKGkpIGRbaV0gPSBkW2ktMV07CiAgICAgICAgICAgICAgICBkW2ldICs9IGFbaV07CiAgICAgICAgfQogICAgICAgIGxsIGN1ciA9IHMtMTsKICAgICAgICBsbCBhbnMgPSAwOwogICAgICAgIHdoaWxlKFMuc2l6ZSgpID4gMikgewoKICAgICAgICAgICAgICAgIGF1dG8gbnh0ID0gUy5sb3dlcl9ib3VuZChjdXIpOwogICAgICAgICAgICAgICAgYXV0byBwcnYgPSBTLmxvd2VyX2JvdW5kKGN1ciArIG4pOwogICAgICAgICAgICAgICAgbnh0Kys7CiAgICAgICAgICAgICAgICBwcnYtLTsKICAgICAgICAgICAgICAgIGxsIE5OID0gMDsKICAgICAgICAgICAgICAgIE5OID0gKm54dDsKICAgICAgICAgICAgICAgIGxsIFBQID0gKnBydjsKICAgICAgICAgICAgICAgIFMuZXJhc2UoUy5maW5kKGN1cikpOwogICAgICAgICAgICAgICAgUy5lcmFzZShTLmZpbmQoY3VyK24pKTsKICAgICAgICAgICAgICAgIGxsIGFhZ2UgPSAxZTk7CiAgICAgICAgICAgICAgICBsbCBwaWNoZSA9IDFlOTsKICAgICAgICAgICAgICAgIGlmKE5OPjApIGFhZ2UgPSBkW05OLTFdOwogICAgICAgICAgICAgICAgaWYoY3VyPjApIGFhZ2UgLT0gZFtjdXIgLSAxXTsKICAgICAgICAgICAgICAgIGlmKGN1cituLTE+MClwaWNoZSA9IGRbY3VyK24tMV07CiAgICAgICAgICAgICAgICBpZihQUCA+IDApIHBpY2hlIC09IGRbUFAtMV07CiAgICAgICAgICAgICAgICBpZihhYWdlIDwgcGljaGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgYW5zICs9IGFhZ2U7CiAgICAgICAgICAgICAgICAgICAgICAgIGxsIFJBID0gTk47CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKFJBID49IG4pIFJBIC09IG47CiAgICAgICAgICAgICAgICAgICAgICAgIGN1ciA9IFJBOwogICAgICAgICAgICAgICAgfWVsc2UgaWYoYWFnZSA+IHBpY2hlKXsKICAgICAgICAgICAgICAgICAgICAgICAgYW5zICs9IHBpY2hlOwogICAgICAgICAgICAgICAgICAgICAgICBsbCBSQiA9IFBQOwogICAgICAgICAgICAgICAgICAgICAgICBpZihSQiA+PSBuKSBSQiAtPSBuOwogICAgICAgICAgICAgICAgICAgICAgICBjdXIgPSBSQjsKICAgICAgICAgICAgICAgIH1lbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGwgUkEgPSBOTjsKICAgICAgICAgICAgICAgICAgICAgICAgaWYoUkEgPj0gbikgUkEgLT0gbjsKICAgICAgICAgICAgICAgICAgICAgICAgbGwgUkIgPSBQUDsKICAgICAgICAgICAgICAgICAgICAgICAgaWYoUkIgPj0gbikgUkIgLT0gbjsKICAgICAgICAgICAgICAgICAgICAgICAgaWYoUkEgPCBSQikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN1ciA9IFJBOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFucyArPSBhYWdlOwogICAgICAgICAgICAgICAgICAgICAgICB9ZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VyID0gUkI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYW5zICs9IGFhZ2U7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY291dCA8PCBhbnMgPDwgZW5kbDsKICAgICAgICByZXR1cm4gMDsKfQo=