#include <iostream>
#include <vector>
#include <map>
#include <cmath>

//#ifdef _DEBUG
//#include <string>
//#include <algorithm>
//#include <time.h>
//#endif

using namespace std;

typedef long long LL;
typedef vector<LL> vLL;
typedef map<LL, LL> mLLLL;

bool try_insert(mLLLL &map_, LL b, LL sum) {
	mLLLL::iterator it = map_.upper_bound(b);
	if(it==map_.begin()  ||  (it != map_.end() && it->second <= sum)) {
		while(it != map_.end() && it->second <= sum) {
			mLLLL::iterator it2 = it;
			it++;
			map_.erase(it2);
		}
		map_[b] = sum;
		return true;
	} else {
		it--;
		if(sum > it->second) {
			map_[b] = sum;
			return true;
		} else {
			return false;
		}
	}
}

//#ifdef _DEBUG
//string bin(LL n) {
//	string res;
//	do {
//		res.push_back('0' + (int)(n&1LL));
//		n>>=1;
//	} while(n>0);
//	reverse(res.begin(), res.end());
//	return res;
//}
//#endif

LL next_with_bits(LL val_to_inc, int bits_required, int level = 0) 
{
//#ifdef _DEBUG_EXTRA_OUT
//	cerr << "starting next_with_bits " << bin(val_to_inc) << " " << bits_required;
//#endif
	if(bits_required == 1) {
		LL res = 1LL;
		while(res <= val_to_inc)
			res <<= 1;
//#ifdef _DEBUG_EXTRA_OUT
//		cerr << "; res : " << bin(res) << endl;
//#endif
		return res;
	}
	LL res = val_to_inc + 1LL;
	int bits_have = 0;
	for(LL t = 1LL; t <= res; t<<=1)
		if(res & t)
			bits_have++;
	if(bits_have==bits_required) {
//#ifdef _DEBUG_EXTRA_OUT
//		cerr << "; res : " << bin(res) << endl;
//#endif
		return res;
	} else if(bits_have < bits_required) {
		for(LL t = 1LL; true; t<<=1) {
			if((res & t) == 0LL) {
				res |= t;
				bits_have++;
				if(bits_have == bits_required) {
//#ifdef _DEBUG_EXTRA_OUT
//					cerr << "; res : " << bin(res) << endl;
//#endif
					return res;
				}
			}
		}
	} else { // bits_have > bits_required
		LL t = 1LL;
		int delta_bits = bits_have - bits_required;
		while(delta_bits > 0) {
			if(res & t) {
				res ^= t; // 1 -> 0
				delta_bits--;
			}
			t <<= 1;
		}
		while((res&t)==0) {
			t <<= 1;
		}
		// delta_bits == 0
		return next_with_bits(res + t - 1LL, bits_required, level+1); // exactly once, no deep recursion; required, because this "+t" can clear too many "1"-s
	}
}

int main(int argc, char* argv[])
{
//// #ifdef _DEBUG
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);
//// #endif
	int n;
	long long m;
	cin >> n >> m;
	int max_bits = log(m + 1.25)/log(2.0);
	vLL data(n+1);
	for(int i=0; i<n; i++)
		cin >> data[i];
	vector<mLLLL> opt(n+1);
	opt[0][0LL] = 0LL;
	opt[1][0LL] = 0LL; // конкретно найперша b-шка (й лише вона) може бути нулем
	for(int i=0; i<n; i++) {
//#ifdef _DEBUG
//		cerr << "started i = " << i << " at " << (clock()*1.0)/CLOCKS_PER_SEC;
//#else
		if(i>1)
			opt[i-1].clear();
//#endif
		for(mLLLL::iterator it = opt[i].begin(); it != opt[i].end(); it++) {
			for(int bits_num = 1; bits_num <= max_bits; bits_num++) {
				LL b = next_with_bits(it->first, bits_num);
				if(b <= m - n + i + 1) {
					try_insert(opt[i+1], b, it->second + data[i] * bits_num);
				}
			}
		}
//#ifdef _DEBUG
//		cerr << "; sz = " << opt[i+1].size() << endl;
//#endif
	}
	cout << opt.back().rbegin()->second << endl;
	return 0;
}

