#include using namespace std; #define int long long int G[10][10]; signed main(){ cin.tie(0); ios::sync_with_stdio(false); int n,m; cin >> n >> m; for(int i = 0; i < m; i++){ int a,b,c; cin >> a >> b >> c; G[a][b] = c; } int ans = 0; vector< vector > dp(1 << n,vector (n,-1)); function< int(int,int) > rec = [&](int S,int u){ if(__builtin_popcount(S) == n) return 0LL; if(dp[S][u] != -1) return dp[S][u]; int res = 0; for(int i = 0; i < n; i++){ if(S == 0){ res = max(res,rec(S | 1 << i,i)); } else if(!(S >> i & 1) && G[u][i]){ res = max(res,rec(S | 1 << i,i) + G[u][i]); } } return dp[S][u] = res; }; cout << rec(0,0) << endl; return 0; }