#品物の並び替え def alllist(text , num_list): if len(num_list) == 1: text += str(num_list[0]) all_list.append(text) else: for i in num_list: text2 = text + str(i) copy = num_list.copy() copy.remove(i) alllist(text2 , copy) N , M = map(int , input().split()) score = [] for i in range(M): score.append(list(map(int , input().split()))) all_list = [] r = [i for i in range(N)] alllist("" , r) total = 0 for t in all_list: sum = 0 for s in score: if t.find(str(s[0])) < t.find(str(s[1])): sum += s[2] total = max(total , sum) print(total)