#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);


int main() {
	cin.sync_with_stdio(false);
	ll N, K;
	cin >> N >> K;
	vector<ll>A(N), B(N);
	rep(i, N)cin >> A[i] >> B[i];
	int r = 31;
	vector<ll>kr(r);
	rep(i, r) {
		if (K >> i | 0 == 0)continue;
		if (i <= 1) {
			kr[i] = K >> i << i;
		}
		else {
			kr[i] = (K >> i << i) | ((1 << (i - 1)) - 1);
		}
		if (kr[i] > K) {
			r = i;
			break;
		}

	}
	vector<ll>v(r);
	rep(i, N) {
		rep(j, r) {
			if ((A[i] | kr[j]) == kr[j]) {
				v[j] += B[i];
			}
		}
	}
	ll ans = 0;
	rep(i, r) {
		ans = max(ans, v[i]);
	}
	cout << ans << endl;


	return 0;
}
