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