import itertools n, m = map(int,input().split()) n = [str(i) for i in range(n)] l1 = list(itertools.permutations(n)) l2 = [list(map(str,input().split())) for _ in range(m)] l = [] for i in l1: x = 0 for j in l2: if i.index(j[0]) < i.index(j[1]): x += int(j[2]) l.append(x) print(max(l))