Digital collectible card games have become very popular recently. So Vova decided to try one of these.

Vova has n cards in his collection. Each of these cards is characterised by its power pi, magic number ci and level li. Vova wants to build a deck with total power not less than k, but magic numbers may not allow him to do so — Vova can't place two cards in a deck if the sum of the magic numbers written on these cards is a prime number. Also Vova cannot use a card if its level is greater than the level of Vova's character.

At the moment Vova's character's level is 1. Help Vova to determine the minimum level he needs to reach in order to build a deck with the required total power.

Input

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100000).

Then n lines follow, each of these lines contains three numbers that represent the corresponding card: pi, ci and li (1 ≤ pi ≤ 1000, 1 ≤ ci ≤ 100000, 1 ≤ li ≤ n).

Output

If Vova won't be able to build a deck with required power, print  - 1. Otherwise print the minimum level Vova has to reach in order to build a deck.

Examples

Input

5 8
5 5 1
1 5 4
4 6 3
1 12 4
3 12 1


Output

4


Input

3 7
4 4 1
5 8 2
5 3 3


Output

2
/*
    Push-Relabel with highest label selection.
    O(N^3)
 */

//created by Whiplash99
import java.io.*;
import java.util.*;
public class A
{
    private static final int INT_MAX=Integer.MAX_VALUE;
    private static final long LONG_MAX=Long.MAX_VALUE;
    private static boolean prime[];
    static class PushRelabel
    {
        int N, source, sink, height[];
        long[] excess, flow[], cap[];
        ArrayList<Integer> next;

        PushRelabel(int N, int source, int sink)
        {
            this.N=N; this.source=source;this.sink=sink;
            excess=new long[N]; height=new int[N];
            flow=new long[N][N]; cap=new long[N][N];
            next=new ArrayList<>();
        }
        void init()
        {
            height[source]=N;
            excess[source]=LONG_MAX;
            for(int i=0;i<N;i++) push(source,i); //pre-flow
        }
        void push(int u, int v)
        {
            long lim=Math.min(excess[u],cap[u][v]-flow[u][v]);
            excess[u]-=lim;
            excess[v]+=lim;
            flow[u][v]+=lim;
            flow[v][u]-=lim;
        }
        void relabel(int u)
        {
            int lim=2*N+1;
            for(int i=0;i<N;i++) if(cap[u][i]-flow[u][i]>0) lim=Math.min(lim,height[i]);
            if(lim<2*N+1) height[u]=lim+1;
        }
        void findNext()
        {
            next.clear(); int max=0;
            for(int i=0;i<N;i++) if(i!=source&&i!=sink&&excess[i]>0) max=Math.max(max,height[i]);
            for(int i=0;i<N;i++) if(height[i]==max&&excess[i]>0&&i!=source&&i!=sink) next.add(i);
        }
        void add(int u, int v, long c){cap[u][v]+=c;}
        long getMaxFlow()
        {
            findNext();
            while (!next.isEmpty())
            {
                for(int u:next)
                {
                    boolean pushed=false;
                    for(int v=0;v<N;v++)
                    {
                        if(excess[u]==0) break;
                        if(cap[u][v]-flow[u][v]>0&&height[u]==height[v]+1)
                        {
                            push(u,v);
                            pushed=true;
                        }
                    }
                    if(!pushed){ relabel(u);break;}
                }
                findNext();
            }

            long maxFlow=0;
            for(int i=0;i<N;i++) maxFlow+=flow[source][i];
            return maxFlow;
        }
    }
    private static int search(int N, int K, int p[], int c[], int lev[])
    {
        int l=1,r=N,mid,ans=-1;
        long sum;

        while (l<=r)
        {
            mid=(l+r)/2; sum=0;

            PushRelabel flows=new PushRelabel(N+2,N,N+1);
            int pos1=-1, max=0;
            for(int i=0;i<N;i++)
            {
                if(c[i]==1&&lev[i]<=mid&&max<p[i])
                {
                    pos1=i;
                    max=p[i];
                }
            }
            for(int i=0;i<N;i++)
            {
                if(lev[i]>mid) continue;
                if(c[i]==1&&i!=pos1) continue;
                if(c[i]%2==1) flows.add(N,i,p[i]);
                else flows.add(i,N+1,p[i]);
                sum+=p[i];
            }
            for(int u=0;u<N;u++)
            {
                if(flows.cap[N][u]==0) continue;
                for(int v=0;v<N;v++)
                {
                    if(flows.cap[v][N+1]==0) continue;
                    if(prime[c[u]+c[v]]) flows.add(u,v,INT_MAX);
                }
            }
            flows.init();
            long maxFlow=flows.getMaxFlow();

            if(K<=sum-maxFlow)
            {
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        return ans;
    }
    private static void sieve()
    {
        Arrays.fill(prime,true);
        prime[0]=prime[1]=false;
        for(int i=2;i<prime.length;i++)
        {
            if(prime[i]&&(long)i*i<prime.length)
                for(int j=i*i;j<prime.length;j+=i)
                    prime[j]=false;
        }
    }
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        prime =new boolean[(int)(2e5+5)];
        sieve();

        String s[]=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        int K=Integer.parseInt(s[1]);

        int[] p=new int[N], c=new int[N], l=new int[N];
        for(i=0;i<N;i++)
        {
            s=br.readLine().trim().split(" ");
            p[i]=Integer.parseInt(s[0]);
            c[i]=Integer.parseInt(s[1]);
            l[i]=Integer.parseInt(s[2]);
        }

        System.out.println(search(N,K,p,c,l));
    }
}