#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define pi pair<ll, ll>
#define pll pair<long long, long long>
#define vi vector<ll>
#define vll vector<long long>
#define vpi vector<pair<ll,ll>>
#define vpll vector<pair<long long, long long>>
#define pb push_back
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)(x).size()
#define forall(it,x) for(auto& it:(x))
#define mp make_pair
pi operator+(pi a, pi b) { return mp(a.ff+b.ff, a.ss+b.ss); }
pi operator-(pi a, pi b) { return mp(a.ff-b.ff, a.ss-b.ss); }
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#pragma GCC optimize("O3,unroll-loops")
#ifdef _WIN32
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#endif
inline int readint() {
char c = getchar_unlocked();
while((c < '0' || c > '9') && c != '-') c = getchar_unlocked();
bool neg = false;
if(c == '-') neg = true, c = getchar_unlocked();
int res = 0;
while(c >= '0' && c <= '9') res = res * 10 + c - '0', c = getchar_unlocked();
return neg? -res : res;
}
char _buf[40];
inline void printint(int n) {
if(n == 0) putchar_unlocked('0');
if(n < 0) putchar_unlocked('-'), n = -n;
int i = 0;
for(; n > 0; n /= 10) _buf[i++] = n % 10 + '0';
while(i--) putchar_unlocked(_buf[i]);
}
ll inf = 2e18;
ll M = 300'000;
ll base = 1<<17;
struct SegTree {
vector<pair<ll, ll>> T, L;
SegTree() {
T.assign(2*base, {0,0});
L.assign(2*base, {0,0});
}
void push(ll v, ll a, ll b, ll l, ll r) {
if(!L[v].ff && !L[v].ss) return;
if(a==b) return;
T[l] = T[l] + L[v];
T[r] = T[r] + L[v];
L[l] = L[l] + L[v];
L[r] = L[r] + L[v];
L[v] = {0,0};
}
void update(ll v, ll a, ll b, ll p, ll k, pi val) {
if(b<p || k<a) return;
if(p<=a && b<=k) {
T[v] = T[v] + val;
L[v] = L[v] + val;
return;
}
ll l = 2*v; ll r = 2*v+1; ll mid = (a+b)/2;
push(v,a,b,l,r);
update(l, a, mid, p,k,val);
update(r, mid+1, b, p,k,val);
T[v] = max(T[l], T[r]);
}
pair<ll, ll> query(ll v, ll a, ll b, ll p, ll k) {
if(b<p || k<a) return {-inf, 0};
if(p<=a && b<=k) {
return T[v];
}
ll l = 2*v; ll r = 2*v+1; ll mid = (a+b)/2;
push(v,a,b,l,r);
return max(query(l,a,mid,p,k), query(r,mid+1,b,p,k));
}
};
ll n, m;
vector<ll> S(M), T(M), C(M);
vector<vector<ll>> bucket(M);
pi calc(ll alpha) {
SegTree st;
pi dp = {0,0};
for(ll i=n-1; i>=0; --i) {
for(auto x : bucket[i]) {
st.update(1,0,base-1,S[x], T[x], {C[x], 0});
}
st.update(1,0,base-1,i,i,{dp.ff - alpha, dp.ss - 1});
for(auto x : bucket[i]) {
dp = max(dp, st.query(1,0,base-1,S[x], T[x]));
}
}
dp.ss *= -1;
return dp;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll K;
n=readint();
m=readint();
K=readint();
ll sum = 0;
for(ll i=0; i<m; ++i) {
S[i] = readint(); T[i]=readint(); C[i]=readint();
S[i]--; T[i] -= 2;
sum += C[i];
bucket[S[i]].pb(i);
}
ll lo = 0;
ll hi = 1e14;
ll res = 0;
while(lo <= hi) {
ll alpha = (lo+hi)/2;
auto dp0 = calc(alpha);
if(dp0.second > K) lo = alpha+1;
else if(dp0.second <= K) {
hi = alpha - 1;
res = dp0.ff + alpha * K;
}
}
cout << sum-res << "\n";
return 0;
}