n, m = map(int, input().split()) X = [] for i in range(m): a, b, s = map(int, input().split()) X.append((a, b, s)) import itertools ans = 0 for p in itertools.permutations(range(n)): q = [0]*n temp = 0 for i, e in enumerate(p): q[e] = i for i in range(m): a, b, s = X[i] if q[a] < q[b]: temp += s ans = max(ans, temp) print(ans)