#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<LL,LL> PLL;
typedef vector<PIL> VPIL;
typedef vector<PLL> VPLL;
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define ALL(c) (c).begin(),(c).end()
#define FOREACH(it,c,i) for(auto it=(c).begin()+(i);it!=(c).end();++it)
#define SIZE(c) (int)(c).size()
LL mx=0,ps,pst,m,a[201],yet[202];
int tc[65536]={},bt=0,n,i,j,h;
int C(ULL a)
{
int r=0;
while(a)
{
r+=tc[a&65535];
a>>=16;
}
return r;
}
int main()
{
for(i=1;i<65536;i<<=1)
for(j=i;j<2*i;++j)
tc[j]=tc[j-i]+1;
scanf("%d%lld",&n,&m);
for(i=0;i<n;++i){
scanf("%lld",a+i);
}
VPLL t1,t2;
t1.PB(MP(-1,0));
for(i=0;i<n;++i){
t1.PB(MP(m,0));
if(a[i]>0)
FOREACH(it,t1,1){
auto p=*(it-1);
pst=p.ST+1;
bt=C(pst);
for(;pst<=it->ST;pst=(pst|(pst+1)),bt++)
t2.PB(MP(pst,p.ND+bt*a[i]));
}
else{
FOREACH(it,t1,1){
auto p=*(it-1);
pst=p.ST+1;
while(pst<=it->ST){
t2.PB(MP(pst,p.ND+C(pst)*a[i]));
pst&=pst-1;
pst=pst+pst-(pst&(pst-1));
if(pst==0)
break;
}
ps=p.ST;
}
}
j=1;
for(h=1;h<SIZE(t2);++h)
if(t2[h].ND>t2[j-1].ND){
t2[j]=t2[h];
++j;
}
t2.resize(j);
// for(auto p:t2)
// printf("%lld %lld\n",p.ST,p.ND);
// printf("\n");
t2.swap(t1);
t2.clear();
}
printf("%lld\n",t1.back().ND);
}