N, M = gets.split.map &:to_i tbl = [0]*100 $<.map{|s| a, b, score = s.split.map &:to_i tbl[a*10+b] = score } p (R=*0...N).permutation.map{|perm| R.map{|i| (i...N).map{|j| tbl[perm[i]*10+perm[j]] }.sum }.sum }.max