#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    auto calc = [&](int mask) {
        long long sum = 0;
        for (int j = 0; j < n; j++) if ((a[j] | mask) == mask) sum += b[j];
        return sum;
    };
    long long ans = calc(k);
    for (int i = 0; i < 31; i++) if (k >> i & 1) {
        int mask = (k ^ (1 << i)) | ((1 << i) - 1);
        ans = max(ans, calc(mask));
    }
    cout << ans << endl;
    return 0;
}
