#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;

using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n, m, K;
	ll memo[100005] = {};
	ll x[1000006] = {};
	ll y[200005] = {};
	ll z[200005] = {};
	string s;
	string s1, s2;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	cin >> a;
	cin >> b;
	for (ll i = 0; i < a; i++)
	{
		cin >> x[i];
		ans += x[i];
		g += x[i];
	}

	//c = log2(b) + 1;
	c = 40;
	h = b;
	//for (ll i = pow(2, ll(log2(b) + 1)); i >= 1; i /= 2)
	for (ll i = pow(2, 40); i >= 1; i /= 2)
	{
		//cout << i << endl;

		for (ll k = 0; k < a; k++)
		{
			if (x[k] - i >= 0)
			{
				y[c]++;
				x[k] -= i;

			}
		}
		if (h - i >= 0)
		{
			memo[c]++;
			h -= i;

		}

		c--;
	}

	//for (int i = 0; i <= log2(b) + 1; i++)
	//{
	//	//cout << y[i];
	//}
	//c = b;
	//d = 0;
	//while (d == 0)
	//{
	//	d = 1;
	//	e = 0;
	//	for (int i = log2(b) + 1; i >= 0; i--)
	//	{
	//		if (pow(2, i) <= c&&y[i] <= a / double(2) - 0.4&&e < (a - y[i] * 2)*pow(2, i) && z[i] == 0)
	//		{
	//			e = (a - y[i] * 2)*pow(2, i);
	//			f = i;
	//			d = 0;
	//		}
	//	}
	//	if (d == 0)
	//	{
	//		z[f] = 1;
	//		ans += (a - y[f] * 2)*pow(2, f);
	//		c -= pow(2, f);
	//	}
	//}
	//c = 0;
	for (ll i = log2(b) + 1; i >= 0; i--)
	{

		if (a - y[i] * 2 > 0)
		{
			z[i] = (a - y[i] * 2)*pow(2, i);
		}
		else
		{
			z[i] = 0;
		}

	}
	g = 0;
	f = 0;
	for (int i = 0; i <= log2(b) + 1; i++)
	{
		//cout << y[i];
	}
	//cout << endl;
	for (ll i = 0; i <= log2(b) + 1; i++)
	{
		//cout << z[i]<<endl;
	}
	//cout << endl;
	
	
	for (ll i = log2(b) + 1; i >= 0; i--)
	{
		if (memo[i] != 0)
		{
			h = 0;
			for (ll k = i - 1; k >= 0; k--)
			{
				h += z[k];
			}
			g = max(g, ans + h + f);
			//cout << ans + h + f << endl;

			f += z[i];
		}

	}
	
	//cout << endl;

	for (int i = 0; i <= log2(b) + 1; i++)
	{
		//cout << memo[i] << endl;
	}
	g = max(g, ans + f);
	

	cout << g << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 12288