#include<bits/stdtr1c++.h>
using namespace std;

int N, M;
vector<pair<int, int> > G[20];
int memo[20][1100000];

int dp(int at, int bm) {
    if (memo[at][bm] != -1) return memo[at][bm];
    if (at == N-1) return 0;
    int res = -2;
    for (pair<int, int> p : G[at]) {
        if (!(bm & (1 << p.first))) {
            int val = dp(p.first, bm | (1 << p.first));
            if (val >= 0)
                res = max(res, p.second + val);
        }
    }
    return memo[at][bm] = res;
}

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    memset(memo, -1, sizeof memo);
    
    cin >> N >> M;
    while (M--) {
        int a, b, c;
        cin >> a >> b >> c;
        G[a].push_back(pair<int, int>(b, c));
    }
    
    cout << dp(0, 1) << endl;
    
    return 0;
}