# coding: utf-8 # yukicoder No.90 品物の並び替え N, M = map(int, input().split()) rule = [[int(i) for i in input().split()] for _ in range(M)] perm = [0] total = 0 ''' 1 ~ (N - 1) 番の品物を順次どの位置に挿入すれば最大になるか を調べていく ''' for i in range(1, N): max_add = -1 for j in range(i + 1): add = 0 for k in perm[j:]: for c in rule: if [i, k] == c[:2]: add += c[2] break for l in perm[:j]: for c in rule: if [l, i] == c[:2]: add += c[2] break if add > max_add: max_add = add ins = j perm.insert(ins, i) total += max_add print(total)