import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int b = sc.nextInt(); int[] xArr = new int[n]; int[] yArr = new int[n]; int[] pArr = new int[n]; TreeMap xCompress = new TreeMap<>(); TreeMap yCompress = new TreeMap<>(); for (int i = 0; i < n; i++) { xArr[i] = sc.nextInt(); yArr[i] = sc.nextInt(); pArr[i] = sc.nextInt(); xCompress.put(xArr[i], null); yCompress.put(yArr[i], null); } int w = 1; for (int x : xCompress.keySet()) { xCompress.put(x, w++); } int h = 1; for (int x : yCompress.keySet()) { yCompress.put(x, h++); } int[][] points = new int[h][w]; int[][] counts = new int[h][w]; for (int i = 0; i < n; i++) { int c = xCompress.get(xArr[i]); int r = yCompress.get(yArr[i]); points[r][c] += pArr[i]; counts[r][c]++; } for (int i = 1; i < h; i++) { for (int j = 1; j < w; j++) { points[i][j] += points[i - 1][j] + points[i][j - 1] - points[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 left = 0; left < w - 1; left++) { for (int right = left + 1; right < w; right++) { int up = 0; for (int j = 0; j < h; j++) { while (up < h) { int score = points[up][right] - points[up][left] - points[j][right] + points[j][left]; if (score > b) { break; } int sum = counts[up][right] - counts[up][left] - counts[j][right] + counts[j][left]; ans = Math.max(ans, sum); up++; } } } } System.out.println(ans); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }