import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np import itertools N,M = map(int,readline().split()) m = map(int,read().split()) ABC = zip(m,m,m) perms = np.array(list(itertools.permutations(range(N)))) score = np.zeros(len(perms), np.int64) for a,b,c in ABC: score[perms[:,a] < perms[:,b]] += c answer = score.max() print(answer)