#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pl4 = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpl4 = vector<pl4>;
using vvpl4 = vector<vpl4>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) sort((a).rbegin(),(a).rend())
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define PREVP(a) prev_permutation((a).begin(),(a).end())
#define NEXTP(a) next_permutation((a).begin(),(a).end())
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Say(a) cout <<(a);
#define Sal(a) cout <<(a)<<endl;
#define dbg(a) cout <<(#a)<<": "<<(a)<<endl;
#define a2l(a) ((ll)(a-97))
#define A2l(a) ((ll)(a-65))
#define l2a(a) ((char)(a+97))
#define l2A(a) ((char)(a+65))
#define DigN2(a) ((llabs(a)==0)?(1):((ll)(log2(double(llabs(a))))+1))
#define DigN10(a) ((llabs(a)==0)?(1):((ll)(log10(double(llabs(a))))+1))
#define Dig2(a,b) (((a)>>(b))&1)

#define int ll

const ll MOD = 1e9+7;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll min(ll a, ll b){if(a>=b) return b;if(a<b) return a;}
ll max(ll a, ll b){if(a>=b) return a;if(a<b) return b;}

ll DigS10(ll n){
    ll m=0;
    FOR(i,0,DigN10(n)-1){
        m+=(ll)((llabs(n)%(ll)(pow(10.0,(double)(i+1))))/(ll)(pow(10.0,(double)i)));
    }
    return m;
}

ll isP(ll n){
    if(n<=1) return 0;
    FOR(i,2,(ll)sqrt(n)){
        if(n%i==0) return 0;
    }
    return 1;
}

ll BinS(vll a,ll b){
    ll min=0,max=a.size()-1,mid=0;
    while(1){
        mid=(min+max)/2;
        if(a[min]==b) return min;
        if(a[mid]==b) return mid;
        if(a[max]==b) return max;
        if(max-min<=2) return -1;
        if(a[mid]<b) min=mid;
        if(a[mid]>b) max=mid;
    }
}

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

signed main() {

    ll N,K;
    cin >>N>>K;
    vll A(N),B(N);
    vll ma(41,-1);
    vll K2(41,-1);
    ma[40]=0;
    FOR(i,0,DigN2(K)-1){
        if(Dig2(K,i)==1){
            ma[i]=0;
            K2[i]=K;
            K2[i]-=(1<<i);
            FOR(j,0,i-1){
                if(Dig2(K2[i],j)==0) K2[i]+=(1<<j);
            }
        }
    }
    FOR(i,0,N-1){
        
        cin >>A[i]>>B[i];
        if((K|A[i])==K){
            ma[40]+=B[i];
        }
        FOR(j,0,DigN2(K)-1){
            if(ma[j]!=-1){
                if((K2[j]|A[i])==K2[j]){
                    ma[j]+=B[i];
                }
            }
        }
    }
    rSORT(ma);
    Sal(ma[0]);

}






Measured memory_bytes: 2176