// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int k, n, m, maxx[200010], tag[200010], ans;
struct node
{
int x, y, c;
}e[50010];
void pushup(int o)
{
maxx[o] = max(maxx[o << 1], maxx[o << 1 | 1]);
}
bool cmp(node a, node b)
{
if (a.y == b.y)return a.x > b.x;
return a.y < b.y;
}
void pushdown(int o)
{
if (tag[o])
{
tag[o << 1] += tag[o];
tag[o << 1 | 1] += tag[o];
maxx[o << 1] += tag[o];
maxx[o << 1 | 1] += tag[o];
tag[o] = 0;
}
}
void update(int o, int l, int r, int x, int y, int v)
{
if (x <= l && r <= y)
{
tag[o] += v;
maxx[o] += v;
return;
}
pushdown(o);
int mid = (l + r) >> 1;
if (x <= mid)update(o * 2, l, mid, x, y, v);
if (y > mid)update(o * 2 + 1, mid + 1, r, x, y, v);
pushup(o);
}
int query(int o, int l, int r, int x, int y)
{
if (x <= l && r <= y)
return maxx[o];
pushdown(o);
int mid = (l + r) >> 1, res = 0;
if (x <= mid)
res = max(res, query(o * 2, l, mid, x, y));
if (y > mid)
res = max(res, query(o * 2 + 1, mid + 1, r, x, y));
return res;
}
int main()
{
//freopen("htam.in","r",stdin);
//freopen("htam.out","w",stdout);
scanf("%d%d%d", &n, &m , &k);
for (int i = 1; i <= k; i++)scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].c);
sort(e + 1, e + 1 + k, cmp);
for (int i = 1; i <= k; i++)
{
int temp = query(1, 1, n, e[i].x, e[i].y), res = 0;
if (temp >= m)continue;
if (temp + e[i].c <= m)res = e[i].c;
else res = m - temp;
ans += res;
update(1, 1, n, e[i].x, e[i].y - 1, res);
}
printf("%d\n", ans);
return 0;
}