#define _CRT_SECURE_NO_WARNINGS
#define __STDC_FORMAT_MACROS
#include <algorithm>
#include <cinttypes>
#include <cstdio>
#include <vector>

using namespace std;
template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int N, K;

int64_t ans = 0;

vector<int> A;
vector<int> B;

int main()
{
    gc(N);
    gc(K);

    for (int i = 0; i < N; i++)
    {
        int a, b;
        gc(a);
        gc(b);
        A.push_back(a);
        B.push_back(b);
    }

    int d = 30;
    bool init = true;
    while (0 <= d)
    {
        int64_t tmp = 0;
        if ((K & 1 << d) || (K == 0 && d == 0))
        {
            tmp = 0;
            if (init)
            {
                // ビットパターンが一致
                for (int i = 0; i < N; i++)
                {
                    if ((A[i] | K) == K) tmp += B[i];
                }
                ans = max(ans, tmp);
                init = false;
            }

            tmp = 0;

            // 自分のフラグを倒す、自分を除く上位ビットのフラグ保持
            // 自分を除く下位ビットのフラグを立てる
            int k = K != 0 ? K ^ (1 << d) | (1 << d) - 1 : 0;

            for (int i = 0; i < N; i++)
            {
                if ((A[i] | k) == k) tmp += B[i];
            }
            ans = max(ans, tmp);
        }
        d--;
    }

    printf("%" PRId64 "\n", ans);
    return 0;
}
