N, M = list(map(int, input().split(' '))) S = [] for i in range(N): S.append([0 for _ in range(N)]) for i in range(M): f, t, s = list(map(int, input().split(' '))) S[f][t] = s # score for each bit vector expressing that each number is used or not dp = [0 for _ in range(1 << N)] for p in range(1 << N): for i in range(N): # if 'i' is not used yet at p, calculate the score when 'i' is used at p if (p & (1 << i)) == 0: score = dp[p] for j in range(N): if (p & (1 << j)) != 0: score += S[j][i] # update the score when 'i' used at p dp[p | (1 << i)] = max(dp[p | (1 << i)], score) # check the score when all the number is used print(dp[(1 << N)-1])