## https://yukicoder.me/problems/no/2040 MOD = 998244353 def main(): N, M = map(int, input().split()) items = [] for _ in range(M): i1, i2, score = map(int, input().split()) items.append((i1, i2, score)) items_map = {} for b, a, score in items: if a not in items_map: items_map[a] = [] items_map[a].append((b, score)) bit_counts = [[] for _ in range(N + 1)] for bit in range(2 ** N): bit_count = 0 for i in range(N): if bit & (1 << i) > 0: bit_count += 1 bit_counts[bit_count].append(bit) dp = [-1] * (2 ** N) dp[0] = 0 for bit_count in range(N): for bit in bit_counts[bit_count]: for j in range(N): if (1 << j) & bit == 0: new_bit = (1 << j) | bit add_score = 0 if j in items_map: for b, score in items_map[j]: if (1 << b) & bit > 0: add_score += score dp[new_bit] = max(dp[new_bit], dp[bit] + add_score) print(dp[2 ** N - 1]) if __name__ == "__main__": main()