N, M, A = map(int, input().split()) sections = [[] for _ in range(N)] for _ in range(M): l, r, p = map(int, input().split()) l -= 1 sections[l].append((r, p)) dp = [-10 ** 9 - 5] * (N + 1) dp[0] = 0 cur_max = 0 for i, s in enumerate(sections): dp[i] = max(dp[i], cur_max - A) cur = dp[i] for r, p in s: dp[r] = max(dp[r], cur + p - (A if r != N else 0)) cur_max = max(cur_max, cur) print(max(dp))