import java.util.Scanner; public class Main_yukicoder90 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); item1 = new int[m]; item2 = new int[m]; score = new int[m]; for (int i = 0; i < m; i++) { item1[i] = sc.nextInt(); item2[i] = sc.nextInt(); score[i] = sc.nextInt(); } max = 0; used = new boolean[n]; perm = new int[n]; permutation(0, n); System.out.println(max); sc.close(); } private static int[] item1; private static int[] item2; private static int[] score; private static int max; private static boolean[] used; private static int[] perm; // {0, 1, 2, 3, ...., n - 1}の並び替えn!通りを生成する private static void permutation(int pos, int n) { if (pos == n) { // perm[] に対する操作 int[] index = new int[n]; for (int i = 0; i < n; i++) { index[perm[i]] = i; } int sc = 0; for (int i = 0; i < item1.length; i++) { if (index[item1[i]] < index[item2[i]]) { sc += score[i]; } } max = Math.max(max, sc); return; } // perm[]のpos番目を0~n-1のどれにするかのループ for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; // iを使ったのでフラグをtrue used[i] = true; permutation(pos + 1, n); // 戻ってきたらフラグを戻す used[i] = false; } } return; } }