#include using namespace std; template bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } int main() { int n, m; cin >> n >> m; vector>> item(n); for (int i = 0; i < m; i++) { int u, v, s; cin >> u >> v >> s; item[v].emplace_back(u, s); } static long long dp[1 << 14]; fill_n(dp, 1 << 14, -1e9); dp[0] = 0; for (int i = 0; i < 1 << n; i++) { for (int j = 0; j < n; j++) if (~i & 1 << j) { long long gain = 0; for (auto p : item[j]) { if (~i & 1 << p.first) continue; gain += p.second; } chmax(dp[i | 1 << j], dp[i] + gain); } } cout << dp[(1 << n) - 1] << endl; }