// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#define add(a,b,c) (e[i]=b,pre[i]=last[a],last[a]=i,w[i]=c)

#define prec 1e-6

#define inf 1e9

using namespace std;

struct edge

{    int u,v,w;

   edge(int u=0,int v=0,int w=0):u(u),v(v),w(w) {}

};

struct simplex

{    double v;

   double a[1205][1205];

   double b[1205];

   double c[1205];

   int basic[1205];

   int nbasic[105];

   void pivot(int l,int e);

   double opt();

   void output();

};

int fcmp(double x)

{    if (fabs(x)<prec)

       return 0;

   return x>0?1:-1;

}

edge ed[1005];

int last[1005];

int pre[2005];

int deg[105];

int e[2005];

int w[2005];

int f[105];

int n,m;

simplex lp;

void simplex::output()

{    int i,j;

   for (i=1;i<=m;++i)

   {    printf("x[%d]=%.2f-",basic[i],b[basic[i]]);

       for (j=1;j<=n;++j)

           printf("%c%.2fx[%d]",j==1?'(':'+',a[basic[i]][nbasic[j]],nbasic[j]);

       printf(")\n");

   }

   printf("maximize ");

   printf("%.2f",v);

   for (i=1;i<=n;++i)

       printf("+%.2fx[%d]",c[nbasic[i]],nbasic[i]);

   printf("\n\n");

}

void simplex::pivot(int l,int e)

{    static double ta[1205][1205];

   static double tb[1205];

   static double tc[1205];

   int i,j;

   memset(ta,0,sizeof(ta));

   memset(tb,0,sizeof(tb));

   memset(tc,0,sizeof(tc));

   tb[e]=b[l]/a[l][e];

   ta[e][l]=1.0/a[l][e];

   for (i=1;i<=n;++i)

       if (nbasic[i]!=e)

           ta[e][nbasic[i]]=a[l][nbasic[i]]/a[l][e];

   for (i=1;i<=m;++i)

   {    tb[basic[i]]=b[basic[i]]-a[basic[i]][e]*tb[e];

       ta[basic[i]][l]=-a[basic[i]][e]*ta[e][l];

       for (j=1;j<=n;++j)

           if (nbasic[j]!=e)

               ta[basic[i]][nbasic[j]]=a[basic[i]][nbasic[j]]-a[basic[i]][e]*ta[e][nbasic[j]];

   }

   v=v+tb[e]*c[e];

   tc[l]=-ta[e][l]*c[e];

   for (i=1;i<=n;++i)

       if (nbasic[i]!=e)

           tc[nbasic[i]]=c[nbasic[i]]-c[e]*ta[e][nbasic[i]];

   for (i=1;i<=n;++i)

       if (nbasic[i]==e)

           nbasic[i]=l;

   for (i=1;i<=m;++i)

       if (basic[i]==l)

           basic[i]=e;

   for (i=1;i<=m;++i)

   {    for (j=1;j<=n;++j)

           a[basic[i]][nbasic[j]]=ta[basic[i]][nbasic[j]];

       b[basic[i]]=tb[basic[i]];

   }

   for (i=1;i<=n;++i)

       c[nbasic[i]]=tc[nbasic[i]];

}

double simplex::opt()

{    double delta;

   int i,l,e;

   while (1)

   {    e=n+m+2;

       for (i=1;i<=n;++i)

           if (fcmp(c[nbasic[i]])>0&&nbasic[i]<e)

               e=nbasic[i];

       if (e==n+m+2)

           return v;

       delta=-1;

       l=n+m+2;

       for (i=1;i<=m;++i)

           if (fcmp(a[basic[i]][e])>0)

           {    double t=b[basic[i]]/a[basic[i]][e];

               if (l==n+m+2||fcmp(t-delta)<0||(fcmp(t-delta)==0&&basic[i]<l))

               {    delta=t;

                   l=basic[i];

               }

           }

       if (l==n+m+2)

           return inf;

       else pivot(l,e);

   }

}

int longest_path()

{    int q[105];

   int i,h,t;

   q[h=t=1]=1;

   while (h<=t)

   {    for (i=last[q[h]];i!=0;i=pre[i])

       {    f[e[i]]=max(f[e[i]],f[q[h]]+w[i]);

           --deg[e[i]];

           if (deg[e[i]]==0)

               q[++t]=e[i];

       }

       ++h;

   }

   return f[n];

}

void buildlp()

{    int i,j;

   for (i=1;i<=n;++i)

       lp.nbasic[i]=i;

   for (i=1;i<=m;++i)

   {    ++lp.c[ed[i].v];

       --lp.c[ed[i].u];

       lp.v+=f[ed[i].v]-f[ed[i].u]-ed[i].w;

   }

   for (i=1;i<=m;++i)

   {    lp.a[n+i][ed[i].v]=-1;

       lp.a[n+i][ed[i].u]=1;

       lp.b[n+i]=f[ed[i].v]-f[ed[i].u]-ed[i].w;

       lp.basic[i]=n+i;

   }

   for (i=1;i<n;++i)

   {    lp.a[n+m+i][i]=-1;

       lp.basic[m+i]=n+m+i;

   }

   lp.a[n+m+n][n]=1;

   lp.basic[m+n]=n+m+n;

   m+=n;

}

int main()

{    int i,a,b,c;

   scanf("%d%d",&n,&m);

   for (i=1;i<=m;++i)

   {    scanf("%d%d%d",&a,&b,&c);

       ++a,++b;

       ++deg[b];

       ed[i]=edge(a,b,c);

       add(a,b,c);

   }

   longest_path();

   buildlp();

   printf("%d\n",(int)lp.opt());

   fclose(stdin);

   fclose(stdout);

   return 0;

}

//蛻?梵?喇ttp://blog.sina.com.cn/s/blog_4a0c4e5d0101glxu.html

// Faster C++ solution for the same problem (measured speedup: 12.44499375238391x):
#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;

const double eps = 1e-8;

const double inf = 19260817.0/0.0;



double con[1005][105];

int idn[1005],idb[105],n,m,head[105],in[105],out[105],now[105];



struct path

{

	int nex,to,length;

}edge[1005];



inline void addedge(int nex, int to, int length, int total)

{

	edge[total].nex = head[nex];

	edge[total].to = to;

	edge[total].length = length;

	head[nex] = total;

}



inline int sgn(double x)

{

	if (x < -eps)

	{

		return -1;

	}

	else if (x > eps)

	{

		return 1;

	}

	return 0;

}



bool eq(double a, double b)

{

	return sgn(b - a) == 0; 

}



void pivot(int u, int b)

{

	swap(idn[u],idb[b]);

	double x = -con[u][b];

	con[u][b] = -1;

	for (int i = 0; i <= n; i++)

	{

		con[u][i] /= x;

	}

	for (int i = 0; i <= m; i++)

	{

		if (sgn(con[i][b]) && i != u);

		else continue;

		x = con[i][b];

		con[i][b] = 0;

		for (int j = 0; j <= n; j++)

		{

			con[i][j] += x * con[u][j];

		}

	}

}



bool simplex()

{

	int x,y;

	while (1)

	{

		x = y = 0;

		double t = inf;

		for (int i = 1; i <= n; i++)

		{

			if (sgn(con[0][i]) == 1 && (!y || idb[i] < idb[y]))

			{

				y = i;

			}

		}

		if (!y)

		{

			break;

		}

		for (int i = 1; i <= m; i++)

		{

			if (sgn(con[i][y]) == -1)

			{

				t = min(t,-con[i][0] / con[i][y]);

			}

		}

		for (int i = 1; i <= m; i++)

		{

			if (sgn(con[i][y]) == -1 && eq(-con[i][0] / con[i][y],t) && (!x || idn[i] < idn[x]))

			{

				x = i;

			}

		}

		pivot(x,y);

	}

	return 0;

}



bool init()

{

	static double c[105];

	int x = 0;

	for (int i = 1; i <= m; i++)

	{

		if (con[i][0] < con[x][0])

		{

			x = i;

		}

	}

	if (!x)

	{

		return 0;

	}

	for (int i = 1; i <= n; i++)

	{

		c[i] = con[0][i];

		con[0][i] = 0;

	}

	idb[++n] = 0;

	con[0][n] = -1;

	for (int i = 1; i <= m; i++)

	{

		con[i][n] = 1;

	}

	pivot(x,n);

	simplex();

	for (int i = 1; i <= n; i++)

	{

		if (idn[i] == 0)

		{

			for (int j = 1; j <= n; j++)

			{

				if (sgn(con[i][j]))

				{

					pivot(i,j);

					break;

				}

			}

		}

	}

	for (int i = 1; i < n; i++)

	{

		if (idb[i] == 0)

		{

			swap(idb[i],idb[n]);

			for (int j = 1; j <= m; j++)

			{

				swap(con[j][i],con[j][n]);

			}

			break;

		}

	}

	n--;

	for (int i = 0; i <= n; i++)

	{

		con[0][i] = 0;

	}

	for (int i = 1; i <= m; i++)

	{

		if (idn[i] <= n)

		{

			for (int j = 0; j <= n; j++)

			{

				con[0][j] += con[i][j] * c[idn[i]];

			}

		}

	}

	for (int i = 1; i <= n; i++)

	{

		if (idb[i] <= n)

		{

			con[0][i] += c[idb[i]];

		}

	}

	return 0;

}



int main()

{

	int p,s,t,l,total,e;

	scanf("%d%d",&n,&m);

	total = e = 0;

	p = 1;

	memset(head,-1,sizeof(head));

	for (int i = 1; i <= n; i++)

	{

		idb[i] = i;

	}

	for (int i = 1; i <= m; i++)

	{

		scanf("%d%d%d",&s,&t,&l);

		s++;

		t++;

		idn[i] = i + n;

		con[i][s] = -1;

		con[i][t] = 1;

		con[i][0] = -l;

		total += l;

		con[0][s]--;

		con[0][t]++;

		in[t]++;

		out[s]++;

		addedge(s,t,l,i - 1);

	}

	while (e < m)

	{

		for (int i = head[p]; i != -1; i = edge[i].nex)

		{

			now[edge[i].to] = max(now[p] + edge[i].length,now[edge[i].to]);

			in[edge[i].to]--;

			e++;

		}

		in[p] = -1;

		for (int i = 2; i <= n; i++)

		{

			if (!in[i])

			{

				p = i;

				break;

			}

		}

	}

	m++;

	idn[m] = n + m;

	con[m][n] = -1;

	con[m][0] = now[n];

	init();

	simplex();

	printf("%.0f\n",con[0][0] - total);

	return 0;

}