# coding: utf-8 # yukicoder No.90 品物の並び替え from itertools import permutations from itertools import combinations def p_score(p, rule): score = 0 for i in combinations(p, 2): for c in rule: if list(i) == c[:2]: score += c[2] break return score N, M = map(int, input().split()) rule = [[int(i) for i in input().split()] for _ in range(M)] max_score = -1 # 総当たり for p in permutations(range(N)): score = p_score(p, rule) if score > max_score: max_score = score print(max_score)