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.*;

/*
polyakoff
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int oo = (int) 2e9;
    static final long OO = (long) 4e18;
    static final int MOD = (int) 1e9 + 7;
    static int N = (int) 2e5 + 5;

    static int n, k;
    static int[] p, c, l;
    static boolean[] prime;

    static class Dinic {
        class Edge {
            int u, v, c, f;

            Edge(int u, int v, int c) {
                this.u = u;
                this.v = v;
                this.c = c;
                f = 0;
            }
        }
        int n;
        ArrayList<Edge> edges;
        ArrayList<Integer>[] adj;
        int[] d, ptr;

        Dinic(int n) {
            this.n = n;
            edges = new ArrayList<>();
            adj = new ArrayList[n]; Arrays.setAll(adj, i -> new ArrayList<>());
            d = new int[n];
            ptr = new int[n];
        }

        void addEdge(int u, int v, int c) {
            adj[u].add(edges.size());
            edges.add(new Edge(u, v, c));
            adj[v].add(edges.size());
            edges.add(new Edge(v, u, 0));
        }

        int maxFlow(int s, int t) {
            int flow = 0;
            while (bfs(s, t)) {
                Arrays.fill(ptr, 0);
                int delta;
                while ((delta = dfs(s, t, oo)) != 0)
                    flow += delta;
            }
            return flow;
        }

        boolean bfs(int s, int t) {
            LinkedList<Integer> q = new LinkedList<>();
            q.add(s);
            Arrays.fill(d, oo);
            d[s] = 0;
            while (!q.isEmpty()) {
                int u = q.poll();
                for (int ei : adj[u]) {
                    Edge e = edges.get(ei);
                    if (e.f < e.c && d[e.v] == oo) {
                        q.add(e.v);
                        d[e.v] = d[u] + 1;
                    }
                }
            }
            return d[t] != oo;
        }

        int dfs(int u, int t, int minDelta) {
            if (u == t)
                return minDelta;
            for (; ptr[u] < adj[u].size(); ptr[u]++) {
                int ei = adj[u].get(ptr[u]);
                Edge e = edges.get(ei);
                if (e.f < e.c && d[e.v] == d[u] + 1) {
                    int pushed = dfs(e.v, t, Math.min(minDelta, e.c - e.f));
                    if (pushed != 0) {
                        e.f += pushed;
                        edges.get(ei ^ 1).f -= pushed;
                        return pushed;
                    }
                }
            }
            return 0;
        }
    }

    static void solve() {
        prime = new boolean[N];
        Arrays.fill(prime, true);
        for (int i = 2; i < N; i++) {
            if (prime[i]) {
                if ((long) i * i >= N)
                    continue;
                for (int j = i * i; j < N; j += i)
                    prime[j] = false;
            }
        }

        n = in.nextInt();
        k = in.nextInt();

        p = new int[n];
        c = new int[n];
        l = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = in.nextInt();
            c[i] = in.nextInt();
            l[i] = in.nextInt();
        }

        int low = 1, high = 101;
        while (low < high) {
            int mid = (low + high) / 2;

            ArrayList<Integer> cur = new ArrayList<>();
            int one = -1;
            for (int i = 0; i < n; i++) {
                if (l[i] <= mid) {
                    if (c[i] != 1)
                        cur.add(i);
                    else if (one == -1 || p[i] > p[one])
                        one = i;
                }
            }
            if (one != -1)
                cur.add(one);

            int total = 0;
            for (int i : cur)
                total += p[i];

            Dinic dinic = new Dinic(n + 2);
            int s = n, t = s + 1;
            for (int i : cur) {
                if (c[i] % 2 == 0)
                    dinic.addEdge(s, i, p[i]);
                else
                    dinic.addEdge(i, t, p[i]);
            }
            for (int i : cur) {
                for (int j : cur) {
                    if (c[i] % 2 == 0 && c[j] % 2 == 1 && prime[c[i] + c[j]])
                        dinic.addEdge(i, j, oo);
                }
            }

            int f = dinic.maxFlow(s, t);

            if (total - f < k)
                low = mid + 1;
            else
                high = mid;
        }

        if (low == 101)
            out.println(-1);
        else
            out.println(low);

    }

    public static void main(String[] args) throws FileNotFoundException {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("sometext.txt"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("output.txt"));

        int T = 1;
//        T = in.nextInt();
        while (T-- > 0)
            solve();

//        Thread thread = new Thread(null, () -> {
//            solve();
//        }, "Main", 1 << 28);
//        thread.start();
//        try {
//            thread.join();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

//        out.flush();
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        Integer nextInt() {
            return Integer.parseInt(next());
        }

        Long nextLong() {
            return Long.parseLong(next());
        }

        Double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }

    static void dbg(Object... args) {
        for (Object arg : args)
            out.print(arg + " ");
        out.println();
    }

}