import java.io.*; import java.util.Arrays; class Main{ static final PrintWriter out=new PrintWriter(System.out); static final int INF=Integer.MAX_VALUE/2; public static void main(String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line=br.readLine(); int n=Integer.parseInt(line.split(" ")[0]); int m=Integer.parseInt(line.split(" ")[1]); int[][] score=new int[n][n]; int[][] dp=new int[n*n+1][n*(n-1)/2+1]; Arrays.fill(dp[n*n],INF); dp[n*n][0]=0; while(m-->0){ line=br.readLine(); int a=Integer.parseInt(line.split(" ")[0]); int b=Integer.parseInt(line.split(" ")[1]); score[a][b]=Integer.parseInt(line.split(" ")[2]); } for(int i=n*n-1;i>=0;i--){ for(int j=0;j<=n*(n-1)/2;j++){ if(j==0||(int)i/n==i%n) dp[i][j]=dp[i+1][j]; else dp[i][j]=Math.max(dp[i+1][j],dp[i+1][j-1]+score[(int)i/n][i%n]); } } out.println(dp[0][n*(n-1)/2]); } }