import java.io.*; import java.util.*; public class Main_yukicoder844 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); int m = sc.nextInt(); int a = sc.nextInt(); List> edges = new ArrayList<>(n); for (int i = 0; i < n; i++) { edges.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int l = sc.nextInt(); int r = sc.nextInt(); int p = sc.nextInt(); edges.get(l - 1).add(new Pair(r, p)); } long[][] dp = new long[2][n + 1]; // Arrays.fill(dp[0], Long.MIN_VALUE); // Arrays.fill(dp[1], Long.MIN_VALUE); // dp[0][n] = dp[1][n] = 0; for (int i = n - 1; i > 0; i--) { dp[0][i] = Math.max(dp[0][i + 1], dp[1][i + 1]); dp[1][i] = Math.max(dp[0][i + 1] - a, dp[1][i + 1] - a); for (Pair e : edges.get(i)) { dp[1][i] = Math.max(dp[1][i], dp[1][e.a] + e.b - a); } } dp[1][0] = Math.max(dp[0][1], dp[1][1]); for (Pair e : edges.get(0)) { dp[1][0] = Math.max(dp[1][0], dp[1][e.a] + e.b); } pr.println(dp[1][0]); } static class Pair implements Comparable { int a; int b; Pair(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(Pair o) { int result = Integer.compare(a, o.a); if (result == 0) { result = Integer.compare(b, o.b); } return result; } @Override public int hashCode() { final int prime = 31; int result = a; result = prime * result + b; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof Pair)) return false; Pair o = (Pair) obj; return a == o.a && b == o.b; } @Override public String toString() { // Pair [xxx, xxxx] StringBuilder stmp = new StringBuilder(32); stmp.append("Pair ["); stmp.append(a); stmp.append(','); stmp.append(' '); stmp.append(b); stmp.append(']'); return stmp.toString(); } } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }