N, M = map(int, input().split()) item = list(list(map(int, input().split())) for i in range(M)) ans = 0 from itertools import permutations for i in permutations(range(N), N): ans = max(ans, sum([score if i[item1] > i[item2] else 0 for item1, item2, score in item])) print(ans)