import itertools N, M = map(int, input().split()) score_table = [] for i in range(M): score_table.append(list(map(int, input().split()))) perms = itertools.permutations(list(range(N))) total_score_list = [] for perm in perms: total_score = 0 for [back, forth, score] in score_table: for elem in perm: if elem == forth: break elif elem == back: total_score += score break else: continue total_score_list.append(total_score) print(max(total_score_list))