import itertools N, M = map(int, input().split()) all_pattern = list(itertools.permutations(range(N))) # 順列 result = [0] * len(all_pattern) for _ in range(M): item1, item2, score = map(int, input().split()) for i, pattern in enumerate(all_pattern): sts = False for item in pattern: if item == item2 and not sts: break elif item == item1 and not sts: sts = True elif item == item2 and sts: result[i] += score break print(max(result))