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: index_back = perm.index(back) index_forth = perm.index(forth) if index_back < index_forth: total_score += score total_score_list.append(total_score) print(max(total_score_list))