import sys import itertools N, M = map(int,input().split()) listN = [i for i in range(N)] scores = [[] for _ in range(M)] for i in range(M): a,b,sc = map(int,input().split()) scores[i] = [a,b,sc] scores.sort() ans = 0 for t in itertools.permutations(listN): score = 0 for i in range(N-1): for s in scores: if t[i] == s[0] and t[i+1] == s[1]: score += s[2] break elif s[0] > t[i]: break ans = max(ans,score) print(ans)