#pragma GCC optimize("O3,inline")
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<pair<int, int>, int>> vals;
vector<vector<int>> mem;
struct node {
int s, e, m, v, v1, lazy;
node* l, * r;
node(int _s, int _e) : s(_s), e(_e), m((_s + _e) / 2), v(1e15), v1(0), lazy(0) {
if (s != e)
l = new node(s, m),
r = new node(m + 1, e);
}
void prop() {
if (s == e || lazy == 0) return;
l->v += lazy;
r->v += lazy;
l->lazy += lazy;
r->lazy += lazy;
l->v1 += lazy;
r->v1 += lazy;
lazy = 0;
}
void reset() {
v1 = 1e15, v = 0, lazy = 0;
if (s == e) return;
l->reset();
r->reset();
}
void upd(int a, int b, int x) {
if (b < s || a > e) return;
if (a <= s && b >= e) {
v += x;
v1 += x;
lazy += x;
return;
}
prop();
l->upd(a, b, x);
r->upd(a, b, x);
v = min(l->v, r->v);
v1 = min(l->v1, r->v1);
}
void upds(int n, int x) {
if (s == e) {
v1 = min(v1, x);
return;
}
prop();
if (n <= m) l->upds(n, x);
else r->upds(n, x);
v1 = min(l->v1, r->v1);
}
int qry(int a, int b) {
if (a < 0) return 0;
if (b < s || a > e) return 1e15;
if (a <= s && b >= e) return v;
prop();
return min(l->qry(a, b), r->qry(a, b));
}
int qry1(int a, int b) {
if (b < s || a > e) return 1e15;
if (a <= s && b >= e) return v1;
prop();
return min(l->qry1(a, b), r->qry1(a, b));
}
} *root;
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N, M, K, a, b, c; cin >> N >> M >> K;
for (int i = 0; i < M; i++) {
cin >> a >> b >> c; a--, b--;
vals.push_back({ {b, a}, c });
}
sort(vals.begin(), vals.end());
mem.resize(M, vector<int>(K, -1));
root = new node(0, N);
for (int j = 0; j < K; j++) {
root->reset();
root->upds(N, 0);
for (int i = M - 1; i >= 0; i--) {
//for (int k = 0; k <= N; k++) cout << root->qry1(k, k) << ' ';
//cout << '\n';
//for (int k = 0; k <= N; k++) cout << root->qry(k, k) << ' ';
//cout << '\n';
int crnt = root->qry1(vals[i].first.first, N) - root->qry(vals[i].first.first, vals[i].first.first);
mem[i][j] = crnt;
root->upd(vals[i].first.second + 1, N, vals[i].second);
if (j) root->upds(vals[i].first.second, root->qry(vals[i].first.second, vals[i].first.second) + mem[i][j - 1]);
}
}
vector<int> eee(N, 0);
for (int i = 0; i < M; i++) eee[vals[i].first.first] += vals[i].second;
int crnts = 0;
int ans = 1e15;
for (int i = 0; i < M; i++) {
ans = min(ans, crnts + mem[i][K - 1]);
crnts += vals[i].second;
}
ans = min(ans, crnts);
cout << ans << '\n';
}