#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector A(M), B(M), C(M); for (int i = 0; i < M; i++) { cin >> A[i] >> B[i] >> C[i]; } vector P(N); iota(P.begin(), P.end(), 0); int res = 0; do { int r = 0; for (int i = 0; i < M; i++) { int a = 0, b = 0; for (int j = 0; j < N; j++) { if (A[i] == P[j]) a = j; if (B[i] == P[j]) b = j; } if (a < b) r += C[i]; } res = max(res, r); } while (next_permutation(P.begin(), P.end())); cout << res << '\n'; return 0; }