from operator import itemgetter def update(i, x): while i < n + 1: if x > bit[i]: bit[i] = x i += i & -i def get(i): mx = 0 while i > 0: if mx < bit[i]: mx = bit[i] i -= i & -i return mx n, m, a = map(int, input().split()) ku = [list(map(int, input().split())) for _ in range(m)] ku.sort(key=itemgetter(1)) bit = [0] * (n + 1) dp = [-a] * (n + 1) for l, r, p in ku: if l - 1: dp[r] = max(dp[l - 1] + p - a, get(l - 1) + p - 2 * a, dp[r]) update(r, dp[r]) else: dp[r] = max(p - a, dp[r]) update(r, dp[r]) update(n,dp[n]+a) print(get(n))