N, M = map(int, input().split()) tab = [] for i in range(M): tab.append(list(map(int, input().split()))) def calc(x): ans = 0 for row in tab: if all(c in x for c in row[:2]): if x.index(row[0]) < x.index(row[1]): ans += row[2] return ans a = 1 for i in range(N): a *= i + 1 mx = 0 for i in range(a): lst = [] x = i for j in range(N, 0, -1): x, m = divmod(x, j) lst.append(m) cdt = calc(lst) if cdt > mx: mx = cdt print(mx)