#include <iostream>
using namespace std;

#define out if(1)cout
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define abs(a)   (((a)<0)?(-(a)):(a))

static const int MAXN = 10000001;

typedef long long int i64;
static i64 ar[MAXN];

int main()
{
	int N, M;
	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		int a, b, k;
		cin >> a >> b >> k;
		ar[a] += k;
		ar[b+1] -= k;
	}

	i64 cur = 0;
	i64 max = 0;
	for (int i = 1; i <= N; i++) {
		cur += ar[i];
		if (cur > max) max = cur;
	}
	cout << max << endl;
	return 0;
}

#include <iostream>
using namespace std;

#define out if(1)cout
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define abs(a)   (((a)<0)?(-(a)):(a))

static const int MAXN = 10000001;

typedef long long int i64;
static i64 ar[MAXN];

int main()
{
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		int a, b, k;
		cin >> a >> b >> k;
		ar[a] += k;
		ar[b+1] -= k;
	}

	i64 cur = 0;
	i64 max = 0;
	for (int i = 1; i <= N; i++) {
		cur += ar[i];
		if (cur > max) max = cur;
	}
	cout << max << endl;
	return 0;
}

Improve iostream with stdio unsync: real 0m1.029s -> 0m1.020s user 0m0.538s -> 0m0.569s sys 0m0.311s -> 0m0.262s refs: 148,846,05 -> 53,570,098
Improve iostream with stdio unsync:
real    0m1.029s -> 0m1.020s
user    0m0.538s -> 0m0.569s
sys     0m0.311s -> 0m0.262s
refs:   148,846,05 -> 53,570,098
