#include using namespace std; using VS = vector; using LL = long long; using VI = vector; using VVI = vector; #define ALL(a) begin((a)),end((a)) #define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++) LL ans = 0LL; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, M; cin >> N >> M; using tp = tuple; vectorrules(M); FOR(i, 0, M) { int a, b, c; cin >> a >> b >> c; rules[i] = tp(a, b, c); } VI a(N, 0); iota(ALL(a), 0); do { LL ret = 0; VI b(N); FOR(j, 0, N) { b[a[j]] = j; } for (tp& rule : rules) { int x, y, z; tie(x, y, z) = rule; if (b[x] < b[y]) { ret += z; } } ans = max(ans, ret); } while (next_permutation(ALL(a))); cout << ans << "\n"; return 0; }