#include <iostream>
#include <math.h>
using namespace std;
int main()
{
// 请在此输入您的代码
long long n,q;
cin>>n>>q;
long long sum=0,sum2=0;
for(long long i=1;i<=q;i++){
int t,x,y;
cin>>t>>x>>y;
if(t==1){
sum+=y;
if(x==n){
sum2-=y; //减法 绝对值
}
}
else if(t==2){
sum2+=y;
if(x==n){
sum-=y; //减法 绝对值
}
}
}
if(sum>sum2) cout<<sum;
else cout<<sum2;
return 0;
}