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 row[0] in x and row[1] in x: 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 - 1, -1, -1): x, m = divmod(x, j + 1) while m in lst: m += 1 lst.append(m) cdt = calc(lst) if cdt > mx: mx = cdt print(mx)