import sys from operator import itemgetter input = sys.stdin.readline n, m, a = map(int, input().split()) info = [list(map(int, input().split())) for i in range(m)] info = sorted(info, key = itemgetter(1)) dp = [0]*(n+1) end = 0 max_dp = 0 for i in range(1, n + 1): if info[end][1] == i: while end < m and info[end][1] == i: if i == n: dp[i] = max(dp[i], max_dp, dp[info[end][0] - 1] + info[end][2]) else: dp[i] = max(dp[i], max_dp - a, dp[info[end][0] - 1] + info[end][2] - a) end += 1 max_dp = max(max_dp, dp[i]) else: dp[i] = max_dp - a print(max(dp))