#include //#define int long long using namespace std; using LL = long long; using P = pair; using Tapris = tuple; #define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i) #define REP(i, n) FOR(i, 0, n) #define pb(a) push_back(a) #define all(x) (x).begin(),(x).end() const int INF = (int)1e9; const LL INFL = (LL)1e15; const int MOD = 1e9 + 7; int dy[]={0, 0, 1, -1, 0}; int dx[]={1, -1, 0, 0, 0}; /*************** using variables ***************/ int n, m; vector item1, item2, score; int mt[20][20]; int dp[1<<15]; /**********************************************/ bool contain(int mask, int pos){ if((mask & (1 << pos)) != 0) return true; return false; } signed main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; item1.resize(m); item2.resize(m); score.resize(m); REP(i, m) cin >> item1[i] >> item2[i] >> score[i]; REP(i, (1 << 15)) dp[i] = 0; for(int mask = 1; mask < (1 << n); mask++){ REP(i, n){ if((mask & (1 << i)) != 0){ int sum = 0; REP(j, m){ if(item2[j] == i && (mask & (1 << item1[j])) != 0){ sum += score[j]; } } dp[mask] = max(dp[mask], dp[mask ^ (1 << i)] + sum); } } } cout << dp[(1 << n) - 1] << endl; }