#include "bits/stdc++.h" using namespace std; struct item { int before; int after; long long score; }; int main() { int N, M; long long ANS = 0; vector V; item X[100]; cin >> N >> M; for (int i = 0; i < N; i++) V.push_back(i); for (int i = 0; i < M; i++) { cin >> X[i].before >> X[i].after >> X[i].score; } do { int Y[9] = {}; for (int i = 0; i < N; i++) { Y[V[i]] = i; } long long COUNT = 0; for (int i = 0; i < M; i++) { if (Y[X[i].before] < Y[X[i].after]) COUNT += X[i].score; } ANS = max(ANS, COUNT); } while (next_permutation(V.begin(), V.end())); cout << ANS << endl; }