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