Problem: Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The debts still mean the same but the total sum of the debts now equals 20 rubles.

This task is a generalisation of a described example. Imagine that your group of friends has n people and you know the debts between the people. Optimize the given debts without changing their meaning. In other words, finally for each friend the difference between the total money he should give and the total money he should take must be the same. Print the minimum sum of all debts in the optimal rearrangement of the debts. See the notes to the test samples to better understand the problem.

Input

The first line contains two integers n and m (1 ≤ n ≤ 100; 0 ≤ m ≤ 104). The next m lines contain the debts. The i-th line contains three integers ai, bi, ci (1 ≤ ai, bi ≤ n; ai ≠ bi; 1 ≤ ci ≤ 100), which mean that person ai owes person bi ci rubles.

Assume that the people are numbered by integers from 1 to n.

It is guaranteed that the same pair of people occurs at most once in the input. The input doesn't simultaneously contain pair of people (x, y) and pair of people (y, x).

Output

Print a single integer — the minimum sum of debts in the optimal rearrangement.

Examples

Input

5 3
1 2 10
2 3 1
2 4 1


Output

10


Input

3 0


Output

0


Input

4 3
1 2 1
2 3 1
3 1 1


Output

0

Note

In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10.

In the second sample, there are no debts.

In the third sample, you can annul all the debts.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T>
class Sieve {
 public:
  vector<T> primes;
  vector<bool> is_prime;
  Sieve(int MAX = 1000000) {
    is_prime.resize(MAX + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (long long int i = 2; i * i <= MAX; i++)
      if (is_prime[i])
        for (long long int j = i * i; j <= MAX; j += i) is_prime[j] = false;
    for (long long int i = 2; i <= MAX; i++)
      if (is_prime[i]) primes.push_back(i);
  }
};
template <typename T>
vector<vector<T>> matmul(const vector<vector<T>>& a,
                         const vector<vector<T>>& b) {
  int n = a.size(), m = b[0].size(), k = b.size();
  vector<vector<T>> c(n, vector<T>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int l = 0; l < k; l++) c[i][j] += (a[i][k] * b[k][j]);
    }
  }
  return c;
}
template <typename T>
T extended_euclid(T a, T b, vector<T>& X) {
  if (b == 0) {
    X = {1, 0};
    return a;
  } else {
    T g = extended_euclid(b, a % b, X);
    vector<vector<T>> G = {{0LL, 1LL}, {1LL, -(a / b)}};
    X = matmul<T>(G, X);
    return g;
  }
}
template <typename T>
bool isPrime(T n) {
  if (n <= 1)
    return false;
  else if (n == 2 || n == 3)
    return true;
  else if (n % 2 == 0 || n % 3 == 0)
    return false;
  T x = 5;
  T p = 2;
  while (x * x <= n) {
    if (n % x == 0) return true;
    x += p;
    p = 6 - p;
  }
  return true;
}
template <typename T>
T binpow(T x, T n, T mod = 1000000007) {
  T ans = 1;
  x = x % mod;
  while (n >= 1) {
    if (n & 1) ans = (ans * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return ans;
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <typename T>
class Graph {
 public:
  int n;
  vector<vector<T>> adj;
  vector<int> inc;
  bool directed;
  Graph(int n, bool directed = false) {
    this->n = n;
    adj.resize(n + 1);
    this->directed = directed;
    inc.resize(n + 1);
  }
  void add_edge(int u, int v) {
    adj[u].push_back(v);
    if (!directed) adj[v].push_back(u);
  }
  void add_edge(int u, int v, int w) {
    adj[u].push_back({v, w});
    inc[v]++;
    if (!directed) adj[v].push_back({u, w});
  }
  void solve() {
    vector<int> debt(n + 1, 0);
    for (int i = 1; i <= n; i++) {
      for (auto v : adj[i]) {
        int j = v.first;
        int d = v.second;
        debt[i] += d;
        debt[j] -= d;
      }
    }
    int tot_debt = 0;
    for (int i = 1; i <= n; i++)
      if (debt[i] > 0) tot_debt += debt[i];
    cout << tot_debt << "\n";
  }
};
class DisjointSets {
 public:
  int n;
  vector<int> parent;
  vector<int> rank;
  vector<int> sz;
  DisjointSets(int n, bool Rank = true) {
    this->n = n;
    parent.resize(n + 1, 0);
    (Rank ? rank.resize(n + 1, 1) : sz.resize(n + 1, 1));
  }
  int find(int i) {
    if (i != parent[i]) parent[i] = find(parent[i]);
    return parent[i];
  }
  void UnionByRank(int i, int j) {
    i = find(i);
    j = find(j);
    if (i == j) return;
    if (rank[i] < rank[j]) swap(i, j);
    parent[j] = i;
    rank[i] += rank[j];
  }
  void UnionBySize(int i, int j) {
    i = find(i);
    j = find(j);
    if (i == j) return;
    if (sz[i] < sz[j]) swap(i, j);
    parent[j] = i;
    sz[i] += sz[j];
  }
};
template <typename T>
class SegmentTree {
 public:
  vector<T> t;
  int n, H;
  void init(int n) {
    this->n = n;
    t.resize(2 * n);
    this->H = sizeof(int) * 8 - __builtin_clz(n);
  }
  void build() {
    for (int i = n - 1; i > 0; i--) t[i] = t[i << 1] + t[(i << 1) | 1];
  }
  void update(int pos, T val) {
    for (t[pos += n] += val; pos > 1; pos >>= 1)
      t[pos >> 1] = t[pos] + t[pos ^ 1];
  }
  T query(int l, int r) {
    T res = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) res += t[l++];
      if (r & 1) res += t[--r];
    }
    return res;
  }
};
bool isSubsequenceString(string x, string y) {
  int i = 0, j = 0;
  while (i < x.length() && j < y.length()) x[i] == y[j] ? i++, j++ : i++;
  return (j == y.length());
}
int max(int a, int b, int c) { return max(a, max(b, c)); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  Graph<pair<int, int>> g(n, true);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g.add_edge(u, v, w);
  }
  g.solve();
}