from itertools import permutations N, M = map(int,input().split()) S = [list(map(int,input().split())) for _ in range(M)] print(max([sum([C if T[A] < T[B] else 0 for A, B, C in S]) for T in permutations(range(N))]))