import collections def calc(order, table): score = 0 it1, it2, sc = 0, 1, 2 for tb in table: if order[tb[it1]] < order[tb[it2]]: score += tb[sc] return score def solve(order, idx, used, score, table): if idx == n: score = calc(order, table) else: for i in range(len(used)): if not used[i]: used[i] = True order[i] = idx score = max(solve(order, idx + 1, used, score, table), score) used[i] = False order[i] = -1 return score n, m = [int(x) for x in input().split()] tb = [] for i in range(m): tb += [[int(x) for x in input().split()]] order = [-1] * n used = [False] * n score = solve(order, 0, used, 0, tb) print(score)