// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

class range {
    struct Iterator {
        int val, inc;
        int operator*() {return val;}
        bool operator!=(Iterator& rhs) {return val < rhs.val;}
        void operator++() {val += inc;}
    };
    Iterator i, n;
    public:
    range(int e) : i({0, 1}), n({e, 1}) {}
    range(int b, int e) : i({b, 1}), n({e, 1}) {}
    range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {}
    Iterator& begin() {return i;}
    Iterator& end() {return n;}
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

struct Edge{ int dst, cap, cost; };
typedef vector<Edge> Node;
typedef vector<Node> Graph;
const LL INF = 100000000; // infinity
struct MinCostFlow{
    typedef pair<LL, int> P; // (???????????¢, ???????????????)
    struct Edge{
        int dst, cap, rev;
        LL cost;
        Edge() {}
        Edge(int d, int c, LL cs, int r) : 
            dst(d), cap(c), cost(cs), rev(r) {}
    };
    typedef vector<Edge> Node;
    typedef vector<Node> Graph;
    Graph G;
    MinCostFlow(int N) : G(N) {}
    // from ?????? to ??????????????????cap, ?????¨cost???????????????
    void add_edge(int src, int dst, int cap, LL cost){
        G[src].push_back(Edge(dst, cap, cost, G[dst].size()));
        G[dst].push_back(Edge(src, 0, -cost, G[src].size() - 1));
    }
    // ??????s????????????t????????????f???????°??????¨???????±???????
    // ??????????????´??????-1?????????
    LL min_cost_flow(int s, int t, int f){
        int V = G.size();
        vector<int> prevv(V), preve(V);
        LL res = 0;
        bool first = true;
        while(f > 0){
            vector<LL> dist(V, INF);
            dist[s] = 0;

            REP(_, V) REP(v, V) REP(i, G[v].size()) {
                Edge& e = G[v][i];
                LL ndist = dist[v] + e.cost;
                if(e.cap > 0 && dist[e.dst] > ndist){
                    dist[e.dst] = ndist;
                    prevv[e.dst] = v;
                    preve[e.dst] = i;
                }
            }

            if(dist[t] == INF){
                // ????????\???????????????
                return -1;
            }

            if(dist[t] >= 0) { break; } // OK ???

            int d = f;
            for(int v = t; v != s; v = prevv[v]){
                d = min(d, G[prevv[v]][preve[v]].cap);
            }
            f -= d;

            res += (LL)d * dist[t];
            for(int v = t; v != s; v = prevv[v]){
                Edge& e = G[prevv[v]][preve[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    }
};
int main(){
    iostream_init();
    int N, M;
    while(cin >> N >> M) {
        vector<vector<int>> next(N);
        vector<vector<int>> cost(N);
        REP(i, M) {
            int a, b, c;
            cin >> a >> b >> c;
            next[a].push_back(b);
            cost[a].push_back(c);
        }
        vector<int> dp(N);
        dp[0] = 0;
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < next[i].size(); j++) {
                int ni = next[i][j];
                dp[ni] = max(dp[ni], dp[i] + cost[i][j]);
            }
        }
        int D = dp[N-1];
        MinCostFlow m(N + 2);
        const int SRC = N;
        const int DST = SRC + 1;
        REP(i, N) m.add_edge(SRC, i, INF, 0);
        REP(i, N) REP(j, next[i].size()) {
            m.add_edge(i, next[i][j], 1, -INF - cost[i][j]);
            m.add_edge(i, next[i][j], INF, -cost[i][j]);
        }
        m.add_edge(N-1, DST, INF, D);
        cout << m.min_cost_flow(SRC, DST, INF) + (LL)M * INF << endl;
    }
    return 0;
}

/* vim:set foldmethod=marker: */

Measured memory_bytes: 1400