//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vint kb(32,0);
    int now=0;
    while(k>0){
        kb[now]=k%2;
        k>>=1;
        now++;
    }
    vvint ab(n,vint(32,0));
    vll b(n);
    ll ans = 0;
    REP(i,n){
        int a;
        cin >> a >> b[i];
        now=0;
        while(a>0){
            ab[i][now]=a%2;
            a>>=1;
            now++;
        }
    }
    for(int i=31;i>=-1;i--){
        if(i>=0&&kb[i]==0)continue;
        ll tmp=0;
        REP(x,n){
            bool f = true;
            for(int j=31;j>i;j--){
                if(ab[x][j]>kb[j]){
                    f=false;
                    break;
                }
            }
            if(i>=0&&f){
                if(ab[x][i]==1){
                    f=false;
                }
            }
            if(f)tmp+=b[x];
        }
        ans = max(ans,tmp);
    }

    cout << ans << endl;
    return 0;
}