using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N, K;
    int[] A, B;
    long ans = 0;
    void solve()
    {
        N = cin.nextint;
        K = cin.nextint;
        A = new int[N];
        B = new int[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = cin.nextint;
            B[i] = cin.nextint;
        }
        Array.Sort(A, B);
        int or = 0;


        f = 0;
        while (true)
        {
            if ((1 << f) < K)
            {
                f++;
            }
            else break;
        }
        //f--;
        //WriteLine(f);
        dfs(0, 31, 0);
        WriteLine(ans);
    }
    int f;
    void dfs(long sum, int keta, int H)
    {
        if (keta == -1)
        {
            long tmp = 0;
            for (int i = 0; i < N; i++)
            {
                bool flag = true;
                for (int j = 0; j <= f; j++)
                {
                    if ((H >> j & 1) == 1 && (A[i] >> j & 1) == 1)
                    {
                        flag = false;
                    }
                }
                if (flag && A[i] <= K)
                {
                    tmp += B[i];
                }
            }
            ans = Math.Max(tmp, ans);
        }

        else if ((K >> keta & 1) == 1)
        {
            dfs(sum, keta - 1, H);

            H |= (1 << keta);
            long tmp = 0;
            for (int i = 0; i < N; i++)
            {
                bool flag = true;
                for (int j = 0; j <= f; j++)
                {
                    if ((H >> j & 1) == 1 && (A[i] >> j & 1) == 1)
                    {
                        flag = false;
                    }
                }
                if (flag && A[i] <= K)
                {
                    tmp += B[i];
                }
            }
            ans = Math.Max(tmp, ans);
        }
        else
        {
            dfs(sum, keta - 1, H | (1 << keta));
        }
    }
}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 17876