#include<cmath>
#include<cstdio>
#include<vector>
#include<numeric>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const double EPS=1e-8;

const int M_MAX=1100,N_MAX=1100;

// minimize cx s.t. Ax<=b
enum{SOLVABLE,UNBOUNDED,INFEASIBLE};
int simplex(int m,int n,const double A_in[M_MAX][N_MAX],const double *b,const double *c,double *x){
	static double A[M_MAX+1][N_MAX+M_MAX+1];
	rep(j,n+m+1) A[0][j]=(j<n?c[j]:0);
	rep(i,m) rep(j,n+m) A[i+1][j]=(j<n?A_in[i][j]:i==j-n?1:0);
	rep(i,m) A[i+1][n+m]=b[i];

	int bas[M_MAX+1];
	rep(i,m) bas[i+1]=n+i;
	n+=m;

	while(1){
		int p,q;
		for(q=0;q< n;q++) if(A[0][q]<-EPS) break;
		for(p=1;p<=m;p++) if(A[p][q]> EPS) break;
		for(int i=p+1;i<=m;i++) if(A[i][q]>EPS){
			double ri=A[i][n]/A[i][q],rp=A[p][n]/A[p][q];
			if(ri<rp-EPS || abs(ri-rp)<EPS && bas[i]<bas[p]) p=i;
		}
		if(q>=n) break;
		if(p> m) return UNBOUNDED;

		// pivoting
		rep(i,m+1) if(i!=p) rep(j,n+1) if(j!=q) A[i][j]-=A[p][j]*A[i][q]/A[p][q];
		rep(i,m+1) if(i!=p) A[i][q]=0;
		rep(j,n+1) if(j!=q) A[p][j]/=A[p][q];
		A[p][q]=1;

		bas[p]=q;
	}

	n-=m;
	rep(i,n) x[i]=0;
	for(int i=1;i<=m;i++) if(bas[i]<n) x[bas[i]]=A[i][n+m];

	return SOLVABLE;
}

struct edge{ int v,cost,id; };

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<edge> G[100];
	rep(i,m){
		int u,v,cost; scanf("%d%d%d",&u,&v,&cost);
		G[u].push_back((edge){v,cost,i});
	}

	int d[100]={};
	rep(u,n) rep(i,G[u].size()) {
		int v=G[u][i].v,cost=G[u][i].cost;
		d[v]=max(d[v],d[u]+cost);
	}

	static double A[M_MAX][N_MAX],b[M_MAX],c[N_MAX],x[N_MAX];
	rep(i,n){
		A[i][i]=1;
		b[i]=d[n-1]-d[i];
	}
	rep(u,n) rep(k,G[u].size()) {
		int v=G[u][k].v,cost=G[u][k].cost,i=G[u][k].id;
		A[n+i][n+i]=1;
		A[n+i][u]=1;
		A[n+i][v]=-1;
		b[n+i]=d[v]-d[u]-cost;
	}
	rep(i,m) c[n+i]=-1;

	simplex(n+m,n+m,A,b,c,x);

	printf("%.0f\n",-inner_product(c,c+n+m,x,0.0)+EPS);

	return 0;
}