import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int bb = sc.nextInt(); int[] xs = new int[n]; int[] ys = new int[n]; int[] ps = new int[n]; TreeMap compX = new TreeMap<>(); TreeMap compY = new TreeMap<>(); for (int i = 0; i < n; i++) { xs[i] = sc.nextInt(); ys[i] = sc.nextInt(); ps[i] = sc.nextInt(); compX.put(xs[i], null); compY.put(ys[i], null); } int xIdx = 1; for (int x : compX.keySet()) { compX.put(x, xIdx); xIdx++; } int yIdx = 1; for (int x : compY.keySet()) { compY.put(x, yIdx); yIdx++; } int[][] field = new int[xIdx][yIdx]; int[][] counts = new int[xIdx][yIdx]; for (int i = 0; i < n; i++) { field[compX.get(xs[i])][compY.get(ys[i])] = ps[i]; counts[compX.get(xs[i])][compY.get(ys[i])] = 1; } for (int i = 1; i < xIdx; i++) { for (int j = 1; j < yIdx; j++) { field[i][j] += field[i - 1][j] + field[i][j - 1] - field[i - 1][j - 1]; counts[i][j] += counts[i - 1][j] + counts[i][j - 1] - counts[i - 1][j - 1]; } } int ans = 0; for (int a = 0; a < xIdx - 1; a++) { for (int b = a + 1; b < xIdx; b++) { for (int c = 0; c < yIdx - 1; c++) { for (int d = c + 1; d < yIdx; d++) { if (field[b][d] - field[a][d] - field[b][c] + field[a][c] <= bb) { ans = Math.max(ans, counts[b][d] - counts[a][d] - counts[b][c] + counts[a][c]); } } } } } System.out.println(ans); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }