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