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 JAVA):

Solution:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */





//import com.sun.xml.internal.ws.util.StringUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.Vector;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.LongStream;





/**
 *
 * @author george
 */

public class main {
   
public static boolean isPrime(long n) {
    if(n < 2) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    long sqrtN = (long)Math.sqrt(n)+1;
    for(long i = 6L; i <= sqrtN; i += 6) {
        if(n%(i-1) == 0 || n%(i+1) == 0) return false;
    }
    return true;
}
/*
    private static long f(long l) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

public static boolean contains(final int[] arr, final int key) {
    return Arrays.stream(arr).anyMatch(i -> i == key);
}
 static boolean isSubSequence(String str1, String str2, int m, int n)
    {
       
        if (m == 0) 
            return true;
        if (n == 0) 
            return false;
             
        
        if (str1.charAt(m-1) == str2.charAt(n-1))
            return isSubSequence(str1, str2, m-1, n-1);
 
        
        return isSubSequence(str1, str2, m, n-1);
    }

    static int gcdThing(int a, int b) {
    BigInteger b1 = BigInteger.valueOf(a);
    BigInteger b2 = BigInteger.valueOf(b);
    BigInteger gcd = b1.gcd(b2);
    return gcd.intValue();
}
    public static boolean checkAnagram(String str1, String str2) {
        int i=0;
        for (char c : str1.toCharArray()) {
        i = str2.indexOf(c, i) + 1;
        if (i <= 0) { return false; }
    }
    return true;

}
   */ 
    public static Set primeFactors(int num)
    {
        Set<Integer>Prime=new HashSet<Integer>();
        // Print the number of 2s that divide n
        int tw=2;
        while (num%2==0)
        {
            Prime.add(tw);
            num /= 2;
        }
 
        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(num); i+= 2)
        {
            // While i divides n, print i and divide n
            while (num%i == 0)
            {
                Prime.add(i);
                num/= i;
            }
        }
 
        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (num> 2)
            Prime.add(num);        
        return Prime;
    }
    /*
    public static String Winner(int [] arr)
    {
        int maxsum=-1;
        int temp=0;
        List<Integer> L=Arrays.stream(arr).boxed().collect(Collectors.toList());
        int count=0;
        String winner="First";
        while(L.isEmpty()!=true){
           if(count%2==0){winner="First";
           //take max odd interval
            for (int i = 0; i < L.size(); i++) {
                
            }
            }
           else{winner="Second";
           
           
           
           
           
           
           
           }
           count++;
        }
    
    
    return winner;
    }
    public static String changeCharInPosition(int position, char ch, String str){
    char[] charArray = str.toCharArray();
    charArray[position] = ch;
    return new String(charArray);
    }
    public static boolean CheckCanObtainYfromX(String y,String x){
        boolean cond=true;
        String help="";
        for (int i = 0; i < y.length(); i++) {
            help="";help+=y.charAt(i);
            if(y.contains(help)==false){x=x.replaceFirst(help,"A");cond=false;break;}
            
        }
        return cond;
    }
   public static int LongestPalindrome(String x){
    int n=x.length();
    boolean table[][] = new boolean[n][n];
    int maxLength = 1;
     for (int i = 0; i < n; ++i)
            table[i][i] = true;
   int start = 0;
    for (int i = 0; i < n - 1; ++i) {
            if (x.charAt(i) == x.charAt(i + 1)) {
                table[i][i + 1] = true;
                start = i;
                maxLength = 2;
            }
        }
     for (int k = 3; k <= n; ++k) {
            for (int i = 0; i < n - k + 1; ++i) 
            {
                int j = i + k - 1;
               if (table[i + 1][j - 1] && x.charAt(i) == x.charAt(j)) {
                    table[i][j] = true;
                if (k > maxLength) {
                        start = i;
                        maxLength = k;
                    }
                }
            }
     }
   return maxLength;
   }
   public static long choose(long total, long choose){
    if(total < choose)
        return 0;
    if(choose == 0 || choose == total)
        return 1;
    return choose(total-1,choose-1)+choose(total-1,choose);
}
    public static long bitwiseAdd(int n1, int n2) {
        int x = n1, y = n2;
        int xor, and, temp;
        and = x & y;
        xor = x ^ y;

        while (and != 0) {
            and <<= 1;
            temp = xor ^ and;
            and &= xor;
            xor = temp;
        }
        return (xor%2);
    }
    public static boolean compare(String a,String b){
        for (int i = 0; i < a.length(); i++) {
            if(a.charAt(i)!=b.charAt(i)&&a.charAt(i)!='?'){return false;}
        }
  return true;
    }*/
/*public static boolean isUniqueChars(String str) {
    // short circuit - supposed to imply that
    // there are no more than 256 different characters.
    // this is broken, because in Java, char's are Unicode,
    // and 2-byte values so there are 32768 values
    // (or so - technically not all 32768 are valid chars)
    if (str.length() > 256) {
        return false;
    }
    // checker is used as a bitmap to indicate which characters
    // have been seen already
    int checker = 0;
    for (int i = 0; i < str.length(); i++) {
        // set val to be the difference between the char at i and 'a'
        // unicode 'a' is 97
        // if you have an upper-case letter e.g. 'A' you will get a
        // negative 'val' which is illegal
        int val = str.charAt(i) - 'a';
        // if this lowercase letter has been seen before, then
        // the corresponding bit in checker will have been set and
        // we can exit immediately.
        if ((checker & (1 << val)) > 0) return false;
        // set the bit to indicate we have now seen the letter.
        checker |= (1 << val);
    }
    // none of the characters has been seen more than once.
    return true;
}*/
 /*private static int [] PossibilitiesAsBinaryTruthTable(int n) {
        int rows = (int) Math.pow(2,n);
        int [] possibleTrack=new int[rows];
        int trackPerRow;
        for (int i=0; i<rows; i++) {
            trackPerRow=0;
            for (int j=n-1; j>=0; j--) {
                if(((i/(int) Math.pow(2, j))%2)==0){trackPerRow--;}
                else if(((i/(int) Math.pow(2, j))%2)==1){trackPerRow++;}
            }
            possibleTrack[i]=trackPerRow;
        }
        return possibleTrack;
    }
    //Steins GCD Algo
     public static long gcd(long u, long v)
    {
        long shift;
        if (u == 0)
            return v;
        if (v == 0)
            return u;
        for (shift = 0; ((u | v) & 1) == 0; ++shift) 
        {
            u >>= 1;
            v >>= 1;
        }
        while ((u & 1) == 0)
            u >>= 1;
        do 
        {
            while ((v & 1) == 0)  
                v >>= 1;
 
            if (u > v) 
            {
                long t = v; 
                v = u; 
                u = t;
            }  
            v = v - u;                      
        } while (v != 0);
 
        return u << shift; 
    }
     public static long gcd(long p, long q) {
        if (q == 0) return p;
        else return gcd(q, p % q);
    }*/
    public static void main (String []  args) throws IOException 
    {
        Scanner s=new Scanner(System.in);
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out));
        String nm=br.readLine();
        int n=Integer.parseInt(nm.split(" ")[0]);
        int m=Integer.parseInt(nm.split(" ")[1]);
        String [] abTransactionline=new String[m];
        long [] bankAccount=new long[n];
        int a,b,amount;
        Arrays.fill(bankAccount, 0);
        for (int i = 0; i < m; i++) {
            abTransactionline[i]=br.readLine();
        }
        for (int i = 0; i < m; i++) {
            a=Integer.parseInt(abTransactionline[i].split(" ")[0]);
            b=Integer.parseInt(abTransactionline[i].split(" ")[1]);
            amount=Integer.parseInt(abTransactionline[i].split(" ")[2]);
            --a;--b;
            bankAccount[a]-=amount;bankAccount[b]+=amount;
        }
        long totalDept=0;
        for (int i = 0; i < n; i++) {
            if(bankAccount[i]<0){totalDept+=Math.abs(bankAccount[i]);}
        }
        System.out.print(totalDept);
    }
}