//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
#pragma comment(linker,"/STACK:33554432") /*32Mb*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <cmath>
#include <list>
#include <iomanip>
#include <set>
#include <map>
#include <sstream>
#include <fstream>
#include <sstream>
#include <iterator>
#include <math.h>
using namespace std;

typedef  long long LL;
typedef  unsigned long long ULL;
typedef  long double LD;
typedef  pair<int, int> PII;
typedef  pair<long long, long long> PLL;
typedef vector<int> VI;

#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define RFOR(i,a,b) for(int (i)=(a)-1;(i)>=(b);--(i)) 
#define For(i,a,b) for(int (i)=(a);i<(b);++(i))
#define FoR(i,a,b) for(int (i)=(a)-1;(i)>=(b);--(i)) 
#define MP make_pair
#define MOD 1000000007
#define mod 1000000000
#define INF 1000000007
#define PB push_back
#define eps 1e-8
#define X first
#define Y second

LL n, k;
PLL arr[100010];

int main()
{
	cout.setf(ios::fixed, ios::floatfield);
	cout.precision(9);

	scanf("%lld", &n);
	scanf("%lld", &k);
	For(i, 0, n)
	{
		scanf("%lld", &arr[i].X);
		scanf("%lld", &arr[i].Y);
	}

	int powK = 0;
	LL kk = k;
	while (kk != 0)
	{
		powK++;
		kk = kk >> 1;
	}

	LL ans = 0;
	For(i, 0, powK + 1)
	{
		LL currK;
		if (i == powK)
			currK = k;
		else
		{
			if (((k >> (powK - 1 - i)) & 1) != 1)
				continue;
			currK = k ^ (1 << (powK - 1 - i));
			currK = currK | ((1 << (powK - 1 - i)) - 1);
		}
		LL currAns = 0;
		For(j, 0, n)
		{
			if ((arr[j].X | currK) <= currK)
				currAns += arr[j].Y;
		}
		ans = max(ans, currAns);
	}

	cout << ans << endl;

	return 0;
}