//be name khoda

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define pii pair<ll, ll>
#define mp make_pair
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


const int N = 1e5 + 123;

map <int, int> m;
pii a[N];
int n;

ll work(ll cnt)
{
	ll ans = 0;
	for(int i = 0; i < n; i++)
		if((a[i].first & cnt) == a[i].first)
			ans += a[i].second;
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll k, ans = 0;
	cin >> n >> k;
	int o = 0;
	for(int i = 0; i < n; i++)
	{
		int t, val;
		cin >> t >> val;
		if(m.find(t) == m.end())
		{
			m[t] = o;
			a[o++] = mp(t, val);
		}
		else
			a[m[t]].second += val;
	}
	n = o;
	ll cnt = 0;
	for(ll i = (1LL<<33); i > 0; i /= 2)
	{
		if(k & i)
		{
			ll t = work(cnt + i - 1);
			// cout << i << ' ' << cnt << ' ' << t << endl;
			ans = max(ans, t);
			cnt += i;
		}
	}
	ans = max(ans, work(cnt));
	cout << ans << endl;
	return 0;
}