#!/usr/bin/env python2.7 import sys import itertools def read_n(): return map(int,raw_input().strip().split(" ")) def compute(arr, N): result = 0 for pat in itertools.permutations(range(0, N)): total = 0 for i in range(0, N - 1): for j in range(i + 1, N): total += arr[pat[i]][pat[j]] result = max([total, result]) return result def compute2(scores, left, right): res = 0 for r in right: right2 = list(right) left2 = list(left) right2.remove(r) left2.append(r) childScore = compute2(scores, left2, right2) score = reduce(lambda a,l: a + scores[l][r], left, 0) res = max([score + childScore, res]) return res (N, M) = read_n() arr = [[0 for y in range(0, N)] for x in range(0,N)] for i in range(0,M): (i1, i2, val) = read_n() arr[i1][i2] = val #print compute(arr, N) print compute2(arr, [], range(0, N))