import collections n, m, a = map(int, input().split()) d = collections.defaultdict(int) for _ in range(m): l, r, p = map(int, input().split()) d[(l - 1, r)] = p dp = [-float('inf')] * (n + 1) dp[0] = 0 for last in range(0, n + 1): for nxt in range(last + 1, n): dp[nxt] = max(dp[nxt], dp[last] + d[(last, nxt)] - a) dp[n] = max(dp[n], dp[last] + d[(last, n)]) print(max(dp))