from itertools import permutations N,M = map(int,input().split()) l = [[] for _ in range(N)] ans = 0 for _ in range(M): i,y,s = map(int,input().split()) l[i].append([y,s]) for perm in permutations(range(N)): perm = list(perm) now = 0 for i in range(N): for item,score in l[i]: if item in perm[:i]: now += score ans = max(ans,now) print(ans)