import java.util.*; public class Main_yukicoder357 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); List> prev = new ArrayList<>(); for (int i = 0; i < n; i++) { prev.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int item1 = sc.nextInt(); int item2 = sc.nextInt(); int score = sc.nextInt(); prev.get(item2).add(new Pair(item1, score)); } int[] dp = new int[0x1 << n]; for (int i = 0; i < 0x1 << n; i++) { for (int j = 0; j < n; j++) { if ((i & 0x1 << j) != 0) { continue; } int sum = 0; for (Pair e : prev.get(j)) { if ((i & 0x1 << e.a) != 0) { sum += e.b; } } dp[i | 0x1 << j] = Math.max(dp[i | 0x1 << j], dp[i] + sum); } } System.out.println(dp[(0x1 << n) - 1]); sc.close(); } private static class Pair { int a; int b; Pair(int a, int b) { this.a = a; this.b = b; } } }