from itertools import permutations N, M = map(int, input().split()) items = [list(map(int, input().split())) for _ in range(M)] ans = 0 for p in permutations(range(N)): tot = 0 for i1, i2, score in items: if p.index(i1) < p.index(i2): tot += score ans = max(ans, tot) print(ans)