from itertools import permutations def eval_(N, regs, t): score = 0 for i in range(N): r = regs[t[i]] for tj in t[i:]: score += r[tj] return score def solve(N, regs): max_ = 0 for t in permutations(range(N)): max_ = max(max_, eval_(N, regs, t)) return max_ def main(): N, M = map(int, input().split()) regs = [[0 for i in range(N)] for j in range(N)] for k in range(M): i1, i2, score = map(int, input().split()) regs[i1][i2] = score print(solve(N, regs)) main()