import collections n, m, a = map(int, input().split()) edge = collections.defaultdict(list) for _ in range(m): l, r, p = map(int, input().split()) edge[l - 1].append((r, p)) dp = [-a] * (n + 1) dp[0] = 0 for last in range(0, n + 1): for nxt, score in edge[last]: if nxt == n: dp[nxt] = max(dp[nxt], dp[last] + score) else: dp[nxt] = max(dp[nxt], dp[last] + score - a) print(max(dp))