/*状态转移方程 <pre name="code" class="cpp"> dp[i] = max(dp[i],dp[j] + arr[i].effciency);
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define MAX_N 1000000
#define MAX_M 1000
typedef long long LL;
struct lists{
LL start;
LL endd;
LL effciency;
}arr[MAX_M];
using namespace std;
//input
LL N,R;
int M;
//input
LL ans = 0;
bool cmp(lists a,lists b)
{
if(a.start==b.start)
return a.endd<b.endd;
return a.start<b.start;
}
LL dp[MAX_N];
void solve(){
memset(dp,0,sizeof(dp));
for(int i = 0;i < M;i++){
dp[i] = arr[i].effciency;
}
for(int i = 0;i < M; i++){
for(int j = 0;j < i; j++){
if(arr[i].start - arr[j].endd >= R){
dp[i] = max(dp[i],dp[j] + arr[i].effciency);
}
ans = max(ans,dp[i]);
}
}
printf("%I64d\n",ans);
}
int main()
{
scanf("%I64d%d%I64d",&N,&M,&R);
for(int i = 0;i < M; i++){
scanf("%I64d%I64d%I64d",&arr[i].start,&arr[i].endd,&arr[i].effciency);
}
sort(arr,arr + M,cmp);
solve();
return 0;
}