#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main(){ ll n, m, ans = 0; cin >> n >> m; vector> list(m, vector(3)); vector arr(n); for (int i = 0; i < n; i++) arr[i] = i; for (int i = 0; i < m; i++) cin >> list[i][0] >> list[i][1] >> list[i][2]; do { ll tmp = 0; for (int i = 0; i < m; i++){ int f = -1, b = -1; for (int j = 0; j < n; j++){ if (arr[j] == list[i][0]) f = j; if (arr[j] == list[i][1]) b = j; } if (f < b) tmp += list[i][2]; } ans = max(ans, tmp); }while (next_permutation(arr.begin(), arr.end())); cout << ans << endl; }