#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 100000;
int n,k;
int a[MAX_N], b[MAX_N];

int clr_l(uint v, uint z)
{
  return v & ~((1 << z) - 1);
}

bool flg(uint v, uint z)
{
  return (v & (1 << (z-1))) != 0;
}

int main()
{
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }

  uint64_t max_v = 0;
  uint64_t v;
  for (uint z = 1; z <= 31; z++) {
    if (!flg(k, z)) continue;
    v = 0;
    int uk = clr_l(k, z-1);
    for (int i = 0; i < n; i++) {
      if (flg(a[i], z)) continue;
      int ua = clr_l(a[i], z-1);
      if ((uk | ua) == uk) {
        v += b[i];
      }
    }
    max_v = max(max_v, v);
  }
  v = 0;
  for (int i = 0; i < n; i++)
    if ((k | a[i]) == k) v += b[i];

  max_v = max(v, max_v);

  cout << max_v << endl;

  return 0;
}
