#include using namespace std; template void cmin(T &a, U b) { if (a > b) a = b; } template void cmax(T &a, U b) { if (a < b) a = b; } signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); long N, M; cin >> N >> M; vector> V(M); for (long i = 0; i < M; i++) { long a, b, c; cin >> a >> b >> c; V.at(i) = {a, b, c}; } vector A(N); iota(A.begin(), A.end(), 0); long ans = 0; do { long tmp = 0; for (long i = 0; i < M; i++) { auto [a, b, c] = V.at(i); long x = find(A.begin(), A.end(), a) - A.begin(); long y = find(A.begin(), A.end(), b) - A.begin(); if (x < y) tmp += c; } cmax(ans, tmp); } while (next_permutation(A.begin(), A.end())); cout << ans << "\n"; }