#include <bits/stdc++.h>
using namespace std;
using vll = vector<long long>;

long long calc_score(int idx, int N, long long K, const vll & As, const vll & Bs){
    // 二進数表記での各桁の上から下 idx + 1桁目までが K に含まれ、
    // 下 idx 桁目がゼロである整数（As[i])の価値の和を求める。
    long long head = K >> (idx + 1);
    long long p = ((idx == -1) ? 0 : (1 << idx));
    long long score = 0;
    for (int i = 0; i < N; ++i){
        if (not(As[i] & p) and ((As[i] >> (idx + 1)) | head) == head){
            score += Bs[i];
        }
    }
    return score;
}


long long solve(int N, long long K, const vll & As, const vll & Bs){
    long long ans = 0;
    for (int idx = -1; (1 << idx) <= K; ++idx){
        if ((idx == -1) or K & (1 << idx)) ans = max(ans, calc_score(idx, N, K, As, Bs));
    }
    return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    long long K;
    cin >> N >> K;
    vll As(N);
    vll Bs(N);
    for (int i = 0; i < N; ++i){
        cin >> As[i] >> Bs[i];
    }
    cout << solve(N, K, As, Bs) << endl;
    return 0;
}