import java.util.*; import java.io.*; public class Main { static HashMap[] maps; static int n; static int[] dp; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); n = Integer.parseInt(first[0]); int m = Integer.parseInt(first[1]); maps = new HashMap[n]; for (int i = 0; i < n; i++) { maps[i] = new HashMap<>(); } for (int i = 0; i < m; i++) { String[] line = br.readLine().split(" ", 3); int a = Integer.parseInt(line[0]); int b = Integer.parseInt(line[1]); int score = Integer.parseInt(line[2]); maps[b].put(a, score); } dp = new int[1 << n]; Arrays.fill(dp, -1); System.out.println(dfw((1 << n) - 1)); } static int dfw(int key) { if (key == 0) { return 0; } if (dp[key] != -1) { return dp[key]; } int max = 0; for (int i = 0; i < n; i++) { if (((1 << i) & key) == 0) { continue; } int score = 0; for (Map.Entry entry : maps[i].entrySet()) { int x = entry.getKey(); if (((1 << x) & key) != 0) { score += entry.getValue(); } } score += dfw(key ^ (1 << i)); max = Math.max(max, score); } dp[key] = max; return max; } }