## https://yukicoder.me/problems/no/3424 import heapq def main(): N, T = map(int, input().split()) l_map = {} max_r = 0 for _ in range(N): l, r, p = map(int, input().split()) if l not in l_map: l_map[l] = [] l_map[l].append((r, p)) max_r = max(max_r, r) max_r += 1 queue = [] dp = [0] * (max_r + 1) cum_dp = [0] * (max_r + 1) for t in range(max_r + 1): if t in l_map: for r, p in l_map[t]: heapq.heappush(queue, (-p, r)) while len(queue) > 0 and queue[0][1] < t: heapq.heappop(queue) if len(queue) > 0: p0, _ = queue[0] p0 = -p0 dp[t] = p0 if t - T >= 0: dp[t] = max(dp[t], cum_dp[t - T] + p0) cum_dp[t] = max(cum_dp[t - 1], dp[t]) answer = cum_dp[-1] print(answer) if __name__ == "__main__": main()