import java.util.Scanner; public class Yukicoder90 { static int n, m, buf, max = -1; static int[] item; static int[][] score; static boolean cover = false; public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); m = sc.nextInt(); item = new int[n]; score = new int[m][3]; for (int i = 0; i < m; i++) { for (int j = 0; j < 3; j++) { score[i][j] = sc.nextInt(); } } // 全探索 uwaaaaa(0); System.out.println(max); } static void uwaaaaa(int now) { if (now == n) { buf = 0; for (int i = 0; i < m; i++) { if (compereIndex(score[i][0], score[i][1])) { buf += score[i][2]; } } max = Math.max(max, buf); return; } for (int i = 0; i < n; i++) { cover = true; for (int j = 0; j < now; j++) { if (now != 0 && i == item[j]) { cover = false; break; } } if (cover) { item[now] = i; uwaaaaa(now + 1); } } } static boolean compereIndex(int a, int b) { int aPos = 0, bPos = 0; for (int i = 0; i < n; i++) { if (a == item[i]) aPos = i; if (b == item[i]) bPos = i; } if (aPos < bPos) return true; else return false; } }