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.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class CardGame {

	static final int MAX = (int) 2e5 + 1;
	static final int oo = 1 << 28;
	static boolean[] isPrime;
	static ArrayList<Integer>[] g;
	static int[] p, res[], f[], power, magic, level;
	static int V, s, t, N, K;

	static void sieve() {
		isPrime = new boolean[MAX];
		Arrays.fill(isPrime, true);
		for (int i = 2; i < MAX; i++)
			if (isPrime[i]) {
				if (i * 1L * i < MAX)
					for (int j = i * i; j < MAX; j += i)
						isPrime[j] = false;
			}
	}

	static int EdmondsKarp() {
		f = new int[V][V];
		int mf = 0;
		while (true) {
			p = new int[V];
			Arrays.fill(p, -1);
			Queue<Integer> q = new LinkedList<>();
			q.add(s);
			p[s] = s;
			while (!q.isEmpty()) {
				int u = q.poll();
				if (u == t)
					break;
				for (int v : g[u]) {
					if (res[u][v] > f[u][v] && p[v] == -1) {
						p[v] = u;
						q.add(v);
					}
				}
			}
			if (p[t] == -1)
				break;
			mf += augment(t, oo);
		}
		return mf;
	}

	static int augment(int v, int flow) {
		if (v == s)
			return flow;
		flow = augment(p[v], Math.min(flow, res[p[v]][v] - f[p[v]][v]));
		f[p[v]][v] += flow;
		f[v][p[v]] -= flow;
		return flow;
	}

	static void addEdge(int u, int v, int cost) {
		g[u].add(v);
		g[v].add(u);
		res[u][v] = cost;
	}

	static int buildGraph(int mid) {
		int totalPower = 0;
		ArrayList<Integer> cards = new ArrayList<>();
		int max = -1, maxI = -1;
		for (int i = 0; i < N; i++)
			if (level[i] <= mid) {
				if (magic[i] != 1)
					cards.add(i);
				else if (power[i] > max) {
					max = power[i];
					maxI = i;
				}
			}
		if (max != -1)
			cards.add(maxI);
		res = new int[V][V];
		for (int i = 0; i < V; i++)
			g[i] = new ArrayList<>();
		int m = cards.size();
		for (int i = 0; i < m; i++) {
			totalPower += power[cards.get(i)];
			if ((magic[cards.get(i)] & 1) != 0) {
				int u = cards.get(i);
				addEdge(s, u, power[u]);
				for (int j = 0; j < m; j++) {
					if (i == j)
						continue;
					int v = cards.get(j);
					if (isPrime[magic[u] + magic[v]])
						addEdge(u, v, oo);
				}
			} else
				addEdge(cards.get(i), t, power[cards.get(i)]);
		}
		return totalPower;
	}

	static int BinarySearch() {
		int low = 1, high = 100, ans = -1;
		while (low <= high) {
			int mid = (low + high) >> 1;
			int totalPower = buildGraph(mid);
			int flow = EdmondsKarp();
			System.err.println(flow);
			int res = totalPower - flow;
			System.err.println(res);
			if (res >= K) {
				high = mid - 1;
				ans = mid;
			} else
				low = mid + 1;
		}
		return ans;
	}

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		sieve();
		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();
		}
		V = N + 2;
		s = V - 2;
		t = V - 1;
		g = new ArrayList[V];
		out.println(BinarySearch());
		out.flush();
		out.close();
	}

	static class MyScanner {
		StringTokenizer st;
		BufferedReader br;

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

		public MyScanner(String file) throws IOException {
			br = new BufferedReader(new FileReader(new File(file)));
		}

		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 boolean ready() throws IOException {
			return br.ready();
		}
	}
}