#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 2;
double EPS = 1e-10;

struct segment_tree_min {
	int n; vector<ll> v;
	segment_tree_min(int _n) {
		for (n = 1; n < _n; n *= 2);
		v = vector<ll>(n * 2 - 1, LLONG_MAX);
	}
	void set(int i, ll x) {
		int k = i + n - 1;
		v[k] = x;
		while (k > 0) {
			k = (k - 1) / 2;
			v[k] = min(v[k * 2 + 1], v[k * 2 + 2]);
		}
	}
	ll _get(int i, int j, int k, int l, int r) {
		if (r <= i || j <= l) return LLONG_MAX;
		if (i <= l && r <= j) return v[k];
		ll vl = _get(i, j, k * 2 + 1, l, (l + r) / 2);
		ll vr = _get(i, j, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
	ll get(int i, int j) { return _get(i, j, 0, 0, n); }
};

int main() {
	ll N; int M, K, D, S;
	cin >> N >> M >> K >> D >> S;
	if (N > M) {
		cout << K * D << endl;
		return 0;
	}
	vector<int> a(M), b(M), c(M);
	priority_queue<i_i, vector<i_i>, greater<i_i> > pq;
	for (int i = 0; i < M; i++) {
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
		c[i]--;
		pq.push(i_i(a[i], i));
	}
	int t = S + D;
	pq.push(i_i(t, M));
	segment_tree_min st(N);
	for (int j = 0; j < N; j++)
		st.set(j, 0);
	while (K) {
		int i = pq.top().second; pq.pop();
		if (i < M) {
			int start = max((ll)a[i], st.get(c[i], c[i] + 1));
			st.set(c[i], start + b[i]);
		}
		else {
			K--;
			int start = max((ll)t, st.get(0, N));
			if (K == 0) {
				cout << start - S << endl;
				return 0;
			}
			t = start + D;
			pq.push(i_i(t, M));
		}
	}
}