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 cnt = 1 for i in range(N): cnt *= i + 1 mx = 0 for i in range(cnt): lst = [j for j in range(N)] cdt = [] x = i for j in range(N): x, m = divmod(x, len(lst)) cdt.append(lst.pop(m)) cdt = calc(cdt) if cdt > mx: mx = cdt print(mx)