#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <limits>
#include <cstdlib>
#include <regex>
using namespace std;

double inf = numeric_limits<double>::infinity();

#define REP(i,n) for(int i=0;i<n;i++)
using LL = long long int;
LL GCD(LL a,LL b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LL LCM(LL a,LL b){ return (a/GCD(a,b))*b; }


LL getHoge(LL k) {
    LL hoge = 1;
    while (k != 0) {
        k = k >> 1;
        hoge = hoge << 1;
    }
    hoge = hoge >> 1;
    return hoge - 1;
}

int main() {
    int n;
    LL k;
    
    cin >> n >> k;
    
    LL ans1 = 0, ans2 = 0;
    vector<LL> as, bs;
    
    REP(i,n) {
        LL a, b;
        cin >> a >> b;
        as.push_back(a);
        bs.push_back(b);
    }
    
    if (k == 0) {
        LL ans4 = 0;
        REP(i,n) {
            if (as[i] == 0) {
                ans4 += bs[i];
            }
        }
        cout << ans4 << endl;
        return 0;
    }
    
    
    LL hoge = getHoge(k);
    REP(i,n) {
        if (as[i] <= hoge) {
            ans1 += bs[i];
        }
    }
    
    LL fuga = k - (hoge + 1);
    LL piyo = getHoge(fuga);
    
    
    REP(i,n) {
        if ((as[i] | k) <= k) {
            ans2 += bs[i];
        }
    }
    
    fuga = getHoge(k) + 1;
    piyo = k - fuga;
    while (piyo != 0) {
        LL ans2_tmp = 0;
        LL nyan = getHoge(piyo);
        nyan += fuga;
        
        REP(i,n) {
            if ((nyan | as[i]) <= nyan) {
                ans2_tmp += bs[i];
            }
        }
        ans2 = max(ans2, ans2_tmp);
        fuga += getHoge(piyo) + 1;
        piyo = k - fuga;
    }
    
    cout << max(ans1, ans2) << endl;
}
