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
import java.io.*;
import java.util.*;

public class Main {
    static boolean isPrime (int num) {
        for (int i = 2; i * i <= num; i++)
            if (num % i == 0) return false;
        return true;
    }
    static int [] power, magic, level;
    static int n, k;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        n = sc.nextInt();
        k = sc.nextInt();
        power = new int[n];
        magic = new int[n];
        level = new int[n];
        for (int i = 0; i < n; i++) {
            power[i] = sc.nextInt();
            magic[i] = sc.nextInt();
            level[i] = sc.nextInt();
        }
        int lo = 0, hi = 101, best = hi;
        for (int cnt = 0; cnt <= Math.log(101) / Math.log(2) + 3; cnt++) {
            int mid = lo + ((hi - lo) >> 1);
            if (ok(mid)) {
                best = mid;
                hi = Math.max(lo, mid - 1);
            } else {
                lo = Math.min(hi, mid + 1);
            }
        }

        if (best == 101) out.println(-1);
        else out.println(best);
        out.flush();
        out.close();
    }

    static boolean ok (int maxLevel) {
        Dinic dinic = new Dinic();
        int oneIdx = -1;
        ArrayList<Integer> validIndices = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (magic[i] == 1 && level[i] <= maxLevel && (oneIdx == -1 || power[i] > power[oneIdx])) {
                oneIdx = i;
            } else if (magic[i] != 1 && level[i] <= maxLevel) {
                validIndices.add(i);
            }
        }
        if (oneIdx != -1) validIndices.add(oneIdx);
        int V = validIndices.size();
        dinic.V = V + 2;
        dinic.s = 0;
        dinic.t = dinic.V - 1;
        dinic.res = new int[dinic.V][dinic.V];
        dinic.adjList = new ArrayList[dinic.V];
        for (int i = 0; i < dinic.V; i++) dinic.adjList[i] = new ArrayList<>();
        int all = 0;
        for (int i = 0; i < V; i++) {
            all += power[validIndices.get(i)];
            if ((magic[validIndices.get(i)] & 1) == 0) {
                dinic.res[dinic.s][i + 1] = power[validIndices.get(i)];
                dinic.adjList[dinic.s].add(i + 1);
                dinic.adjList[i + 1].add(dinic.s);
            } else {
                dinic.res[i + 1][dinic.t] = power[validIndices.get(i)];
                dinic.adjList[i + 1].add(dinic.t);
                dinic.adjList[dinic.t].add(i + 1);
            }
        }
        for (int i = 0; i < V; i++) {
            for (int j = i + 1; j < V; j++) {
                if (isPrime(magic[validIndices.get(i)] + magic[validIndices.get(j)])) {
                    if ((magic[validIndices.get(i)] & 1) == 0) {
                        dinic.res[i + 1][j + 1] = dinic.INF;
                        dinic.adjList[i + 1].add(j + 1);
                        dinic.adjList[j + 1].add(i + 1);
                    } else {
                        dinic.res[j + 1][i + 1] = dinic.INF;
                        dinic.adjList[j + 1].add(i + 1);
                        dinic.adjList[i + 1].add(j + 1);
                    }
                }
            }
        }
        return all - dinic.dinic() >= k;
    }

    static class Dinic {

        final int INF = (int)1e6 + 11;
        int V, s, t, res[][];			//input
        ArrayList<Integer>[] adjList;	//input
        int[] ptr, dist;

        Dinic () {}

        int dinic()						//O(V^2E)
        {
            int mf = 0;
            while(bfs())
            {
                ptr = new int[V];
                int f;
                while((f = dfs(s, INF)) != 0)
                    mf += f;
            }
            return mf;
        }


        boolean bfs()
        {
            dist = new int[V];
            Arrays.fill(dist, -1);
            dist[s] = 0;
            Queue<Integer> q = new LinkedList<Integer>();
            q.add(s);
            while(!q.isEmpty())
            {
                int u = q.remove();
                if(u == t)
                    return true;
                for(int v: adjList[u])
                    if(dist[v] == -1 && res[u][v] > 0)
                    {
                        dist[v] = dist[u] + 1;
                        q.add(v);
                    }
            }
            return false;
        }

        int dfs(int u, int flow)
        {
            if(u == t)
                return flow;
            for(int i = ptr[u]; i < adjList[u].size(); i = ++ptr[u])
            {
                int v = adjList[u].get(i);
                if(dist[v] == dist[u] + 1 && res[u][v] > 0)
                {
                    int f = dfs(v, Math.min(flow, res[u][v]));
                    if(f > 0)
                    {
                        res[u][v] -= f;
                        res[v][u] += f;
                        return f;
                    }
                }
            }
            return 0;

        }
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner (FileReader f) {br = new BufferedReader(f);}

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}