#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

#define size(v) v.size()

template <class U, class C> struct ssp {
  struct edge {
    int to;
    U cap;
    C cost;
  };
  const U inf = numeric_limits<U>::max(), eps = 1e-10;
  int n, s, t;
  vector<edge> es;
  vector<vector<int>> g;
  vector<C> d;
  vector<int> pe;
  ssp(int _n, int _s, int _t) : n(_n), s(_s), t(_t), g(n), d(n), pe(n) {}
  void add(int from, int to, U cap, C cost) {
    g[from].push_back(size(es)), es.push_back({to, cap, cost});
    g[to].push_back(size(es)), es.push_back({from, 0, -cost});
  }
  bool spfa() {
    static vector<bool> in(n);
    static vector<int> que;
    fill(begin(d), end(d), numeric_limits<C>::max());
    que.clear();
    d[s] = 0, in[s] = true, que.push_back(s);
    for (int bg = 0; bg < (int)size(que); ) {
      int v = que[bg++];
      in[v] = false;
      for (int id : g[v]) {
        auto&& e = es[id];
        if (e.cap > eps and d[v] + e.cost < d[e.to]) {
          d[e.to] = d[v] + e.cost, pe[e.to] = id;
          if (not in[e.to]) in[e.to] = true, que.push_back(e.to);
        }
      }
    }
    return d[t] < numeric_limits<C>::max();
  }
  pair<U, C> min_cost_max_flow() {
    U flow = 0;
    C cost = 0;
    while (spfa()) {
      U df = inf;
      for (int v = t; v != s; v = es[pe[v] ^ 1].to) df = min(df, es[pe[v]].cap);
      for (int v = t; v != s; v = es[pe[v] ^ 1].to)
        es[pe[v]].cap -= df, es[pe[v] ^ 1].cap += df;
      flow += df, cost += df * d[t];
    }
    return {flow, cost};
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> x(m), y(m), s(m);
  for (int i = 0; i < m; ++i) {
    cin >> x[i] >> y[i] >> s[i];
    s[i] = -s[i];
  }
  auto f = [&](double l) {
    ssp<double, double> g(n + 2, n, n + 1);
    vector<double> b(n);
    b[0] = 1, b[n - 1] = -1;
    double off = 0;
    for (int i = 0; i < m; ++i) {
      b[x[i]] -= l;
      b[y[i]] += l;
      off += l * s[i];
      g.add(x[i], y[i], 1 - l, s[i]);
    }
    double sb = 0;
    for (int v = 0; v < n; ++v) {
      if (b[v] > g.eps) {
        g.add(g.s, v, b[v], 0);
        sb += b[v];
      } else if (b[v] < -g.eps) {
        g.add(v, g.t, -b[v], 0);
      }
    }
    double flow, cost;
    tie(flow, cost) = g.min_cost_max_flow();
    return flow + g.eps < sb ? 0 : -(off + cost);
  };
  double l = 1e-4;
  auto a = (f(0) - f(l)) / l;
  cout << (int)round(a) << '\n';
}


### Prompt

In cpp, your task is to solve the following problem:

A video game company called ICPC (International Company for Playing and Competing) is now developing a new arcade game. The new game features a lot of branches. This makes the game enjoyable for everyone, since players can choose their routes in the game depending on their skills. Rookie players can choose an easy route to enjoy the game, and talented players can choose their favorite routes to get high scores.

In the game, there are many checkpoints connected by paths. Each path consists of several stages, and completing stages on a path leads players to the next checkpoint. The game ends when players reach a particular checkpoint. At some checkpoints, players can choose which way to go, so routes diverge at that time. Sometimes different routes join together at a checkpoint. The paths between checkpoints are directed, and there is no loop (otherwise, players can play the game forever). In other words, the structure of the game can be viewed as a DAG (directed acyclic graph), when considering paths between checkpoints as directed edges.

Recently, the development team completed the beta version of the game and received feedbacks from other teams. They were quite positive overall, but there are some comments that should be taken into consideration. Some testers pointed out that some routes were very short compared to the longest ones. Indeed, in the beta version, the number of stages in one play can vary drastically depending on the routes. Game designers complained many brilliant ideas of theirs were unused in the beta version because of the tight development schedule. They wanted to have more stages included in the final product.

However, it’s not easy to add more stages. this is an arcade game – if the playing time was too long, it would bring down the income of the game and owners of arcades would complain. So, the longest route of the final product can’t be longer than that of the beta version. Moreover, the producer of the game didn’t want to change the structure of paths (i.e., how the checkpoints connect to each other), since it would require rewriting the scenario, recording voices, creating new cutscenes, etc.

Considering all together, the producer decided to add as many new stages as possible, while keeping the maximum possible number of stages in one play and the structure of paths unchanged. How many new stages can be added to the game?



Input

N M
x1 y1 s1
.
.
.
xM yM sM


The first line of the input contains two positive integers N and M (2 ≤ N ≤ 100, 1 ≤ M ≤ 1000). N indicates the number of checkpoints, including the opening and ending of the game. M indicates the number of paths between checkpoints.

The following M lines describe the structure of paths in the beta version of the game. The i-th line contains three integers xi , yi and si (0 ≤ xi < yi ≤ N - 1, 1 ≤ si ≤ 1000), which describe that there is a path from checkpoint xi to yi consists of si stages. As for indices of the checkpoints, note that 0 indicates the opening of the game and N - 1 indicates the ending of the game. You can assume that, for every checkpoint i, there exists a route from the opening to the ending which passes through checkpoint i. You can also assume that no two paths connect the same pair of checkpoints.

Output

Output a line containing the maximum number of new stages that can be added to the game under the following constraints:

* You can’t increase the maximum possible number of stages in one play (i.e., the length of the longest route to the ending).
* You can’t change the structure of paths (i.e., how the checkpoints connect to each other).
* You can’t delete any stage that already exists in the beta version.

Examples

Input

3 3
0 1 5
1 2 3
0 2 2


Output

6


Input

2 1
0 1 10


Output

0


Input

4 6
0 1 5
0 2 5
0 3 5
1 2 5
1 3 5
2 3 5


Output

20

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

#define size(v) v.size()

template <class U, class C> struct ssp {
  struct edge {
    int to;
    U cap;
    C cost;
  };
  const U inf = numeric_limits<U>::max(), eps = 1e-10;
  int n, s, t;
  vector<edge> es;
  vector<vector<int>> g;
  vector<C> d;
  vector<int> pe;
  ssp(int _n, int _s, int _t) : n(_n), s(_s), t(_t), g(n), d(n), pe(n) {}
  void add(int from, int to, U cap, C cost) {
    g[from].push_back(size(es)), es.push_back({to, cap, cost});
    g[to].push_back(size(es)), es.push_back({from, 0, -cost});
  }
  bool spfa() {
    static vector<bool> in(n);
    static vector<int> que;
    fill(begin(d), end(d), numeric_limits<C>::max());
    que.clear();
    d[s] = 0, in[s] = true, que.push_back(s);
    for (int bg = 0; bg < (int)size(que); ) {
      int v = que[bg++];
      in[v] = false;
      for (int id : g[v]) {
        auto&& e = es[id];
        if (e.cap > eps and d[v] + e.cost < d[e.to]) {
          d[e.to] = d[v] + e.cost, pe[e.to] = id;
          if (not in[e.to]) in[e.to] = true, que.push_back(e.to);
        }
      }
    }
    return d[t] < numeric_limits<C>::max();
  }
  pair<U, C> min_cost_max_flow() {
    U flow = 0;
    C cost = 0;
    while (spfa()) {
      U df = inf;
      for (int v = t; v != s; v = es[pe[v] ^ 1].to) df = min(df, es[pe[v]].cap);
      for (int v = t; v != s; v = es[pe[v] ^ 1].to)
        es[pe[v]].cap -= df, es[pe[v] ^ 1].cap += df;
      flow += df, cost += df * d[t];
    }
    return {flow, cost};
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> x(m), y(m), s(m);
  for (int i = 0; i < m; ++i) {
    cin >> x[i] >> y[i] >> s[i];
    s[i] = -s[i];
  }
  auto f = [&](double l) {
    ssp<double, double> g(n + 2, n, n + 1);
    vector<double> b(n);
    b[0] = 1, b[n - 1] = -1;
    double off = 0;
    for (int i = 0; i < m; ++i) {
      b[x[i]] -= l;
      b[y[i]] += l;
      off += l * s[i];
      g.add(x[i], y[i], 1 - l, s[i]);
    }
    double sb = 0;
    for (int v = 0; v < n; ++v) {
      if (b[v] > g.eps) {
        g.add(g.s, v, b[v], 0);
        sb += b[v];
      } else if (b[v] < -g.eps) {
        g.add(v, g.t, -b[v], 0);
      }
    }
    double flow, cost;
    tie(flow, cost) = g.min_cost_max_flow();
    return flow + g.eps < sb ? 0 : -(off + cost);
  };
  double l = 1e-4;
  auto a = (f(0) - f(l)) / l;
  cout << (int)round(a) << '\n';
}


```