import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int b = sc.nextInt(); TreeMap compX = new TreeMap<>(); TreeMap compY = new TreeMap<>(); Point[] points = new Point[n]; for (int i = 0; i < n; i++) { points[i] = new Point(sc.nextInt(), sc.nextInt(), sc.nextInt()); compX.put(points[i].x, null); compY.put(points[i].y, null); } int xx = 1; for (int x : compX.keySet()) { compX.put(x, xx); xx++; } int yy = 1; for (int x : compY.keySet()) { compY.put(x, yy); yy++; } int[][] scores = new int[xx][yy]; int[][] counts = new int[xx][yy]; for (Point p : points) { scores[compX.get(p.x)][compY.get(p.y)] += p.value; counts[compX.get(p.x)][compY.get(p.y)] ++; } for (int i = 1; i < xx; i++) { for (int j = 1; j < yy; j++) { scores[i][j] += scores[i - 1][j] + scores[i][j - 1] - scores[i - 1][j - 1]; counts[i][j] += counts[i - 1][j] + counts[i][j - 1] - counts[i - 1][j - 1]; } } int max = 0; for (int i = 1; i < xx; i++) { for (int j = i; j < xx; j++) { int right = 1; for (int k = 1; k < yy; k++) { while (right < yy && scores[j][right] - scores[j][k - 1] - scores[i - 1][right] + scores[i - 1][k - 1] <= b) { max = Math.max(max, counts[j][right] - counts[j][k - 1] - counts[i - 1][right] + counts[i - 1][k - 1]); right++; } } } } System.out.println(max); } static class Point { int x; int y; int value; public Point(int x, int y, int value) { this.x = x; this.y = y; this.value = value; } } } 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 String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }