void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.math;

  int n, k; rd(n, k);
  auto a=new long[n];
  auto b=new long[n];
  foreach(i; 0..n) rd(a[i], b[i]);

  long mx=0;
  foreach(pos; 0..32){
    long vsum=0;
    if(k&(1<<pos))foreach(i; 0..n){
      if(a[i]&(1<<pos)) continue;
      bool ok=true;
      foreach(j; (pos+1)..32){
        ok &= (((k&(1<<j)) | (a[i]&(1<<j))) == (k&(1<<j))); 
      }
      if(ok) vsum+=b[i];
    }
    mx=max(mx, vsum);
  }

  long mx2=0;
  foreach(i; 0..n){
    bool ok=true;
    foreach(j; 0..32){
      ok &= (((k&(1<<j)) | (a[i]&(1<<j))) == (k&(1<<j)));
    }
    if(ok) mx2+=b[i];
  }

  writeln(max(mx, mx2));
}


void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}