import itertools n, m = map(int, input().split()) x = list(range(n)) y = list(itertools.permutations(x)) listA = [] listB = [] listC = [] listD = [] for i in range(1, m + 1): listA.append(list(map(int, input().split()))) listE = listA[i - 1] listB.append(listE[0]) listC.append(listE[1]) listD.append(listE[2]) sum = 0 for z in y: list(z) temp = 0 for w in range(0, m): if z.index(listB[w]) < z.index(listC[w]): temp += listD[w] sum = max(sum, temp) print(sum)