from itertools import permutations n,m=map(int,input().split()) lis=[list(map(int,input().split())) for _ in range(m)] ans=[] for per in permutations(range(n)): tmp=0 per=list(per) for x,y,point in lis: if per.index(x)>per.index(y): tmp+=point ans.append(tmp) print(max(ans))