N,M,a = map(int,input().split()) D = [[] for _ in range(N+1)] for _ in range(M): l,r,p = map(int,input().split()) D[r].append((l,p)) dp = [0]*(N+1) for i in range(1,N+1): dp[i] = dp[i-1] if len(D[i])>0: for l,p in D[i]: dp[i] = max(dp[i],dp[l-1]+p) L = [0]*(N+1) d = dp[N] for i in range(N,0,-1): if d==dp[i]>dp[i-1]: r = i for l0,p0 in D[i]: if dp[i]==dp[l0-1]+p0: l = l0 p = p0 break d -= p L[r] = 1 L[l-1] = 1 L[0] = 0 L[N] = 0 ans = max(0,dp[N]-sum(L)*a) print(ans)