n,m,a = map(int,input().split()) query = [[] for i in range(n+5)] for _ in range(m): l,r,p = map(int,input().split()) query[r].append([l,p]) dp = [0]*(n+5) ans = 0 for i in range(1,n+1): dp[i] = ans-a for l,p in query[i]: num = dp[l-1]+p if i != n: num -= a dp[i] = max(dp[i],num) ans = max(ans,dp[i]) print(ans)