import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 2*10^^9 + 7;

void main() {
    int n, k; scan(n, k);
    auto a = new int[](n);
    auto b = new int[](n);
    foreach (i ; 0 .. n) {
        int ai, bi; scan(ai, bi);
        a[i] = ai, b[i] = bi;
    }

    long ans;

    foreach (j ; 0 .. n) {
        if ((~k & a[j]) == 0) {
            ans += b[j];
        }
    }

    foreach (i ; 0 .. 32) {
        if (k & (1 << i)) {
            long tmp;
            int ks = k ^ (1 << i) | ((1<<i) - 1);
            debug {
                writefln("%16b", ks);
            }
            foreach (j ; 0 .. n) {
                if ((~ks & a[j]) == 0) {
                    tmp += b[j];
                }
            }
            ans = max(ans, tmp);
        }
    }

    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
