from itertools import permutations N, M = map(int, input().split()) S = [] for _ in range(M): s = list(map(int, input().split())) S.append(s) A = [i for i in range(N)] MAX = 0 for v in permutations(A): SUM = 0 idx = [0] * N for a in A: idx[a] = v.index(a) for s in S: index1 = idx[s[0]] index2 = idx[s[1]] if index1 < index2: SUM += s[2] MAX = max(MAX, SUM) print(MAX)