N, M = map(int, input().split()) item = [list(map(int, input().split())) for i in range(M)] from itertools import product ans = 0 from collections import deque for i in product(range(2), repeat=M): X = [[] for i in range(N)] Y = 0 for j in range(M): if i[j]: item1, item2, score = item[j] X[item1] += [item2] Y += score for j in range(N): visited = [0] * N visited[j] = 1 que = deque([j]) while que and Y: q = que.popleft() for x in X[q]: if x == j: Y = 0 break if visited[x] == 0: visited[x] = 1 que.append(x) if Y == 0: break ans = max(ans, Y) print(ans)