#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int l[1010],r[1010]={-1000000000},val[1010],f[1010];
void swap(int& a,int& b)
{
int temp;
temp=a;
a=b;
b=temp;
}
int main(void)
{
freopen("milkprod.in","r",stdin);
freopen("milkprod.out","w",stdout);
int i,j,n,lim,rest,temp;
cin>>lim>>n>>rest;
for (i=1;i<=n;i++)
cin>>l[i]>>r[i]>>val[i];
for (i=1;i<n;i++)
for (j=1;j<=n-i;j++)
if (r[j]>r[j+1])
{
swap(l[j],l[j+1]);
swap(r[j],r[j+1]);
swap(val[j],val[j+1]);
}
for (i=1;i<=n;i++)
{
f[i]=f[i-1];
for (j=0;j<i;j++)
{
if (r[j]+rest<=l[i])
{
temp=f[j]+val[i];
if (f[i]<temp)
f[i]=temp;
}
}
}
cout<<f[n]<<endl;
return(0);
}