using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); var map = NArr(m); var pts = new int[n, n]; foreach (var list in map) { pts[list[0], list[1]] = list[2]; } var ans = 0; Permutate(n, list => { var sub = 0; for (var i = 0; i < list.Length; ++i) for (var j = i + 1; j < list.Length; ++j) { sub += pts[list[i], list[j]]; } ans = Math.Max(ans, sub); }); WriteLine(ans); } static void Permutate(int n, Action action) { var seed = new int[n]; for (var i = 0; i < n; ++i) seed[i] = i; var used = new bool[n]; var perm = new int[n]; Permutate(0, seed, perm, used, action); } static void Permutate(int pos, int[] seed, int[] perm, bool[] used, Action action) { if (pos == used.Length) action(perm); for (var i = 0; i < used.Length; ++i) { if (used[i]) continue; perm[pos] = seed[i]; used[i] = true; Permutate(pos + 1, seed, perm, used, action); used[i] = false; } } }