#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define int long long
#define P pair<int,int>

const int MAX_V = 18;
const int INF = 1e18;

int V,E;
int d[MAX_V][MAX_V];
int dp[1 << MAX_V][MAX_V];

int rec(int S, int v){
    if(dp[S][v] >= 0){
        return dp[S][v];
    }

    if(S == (1 << V) - 1 && v == 0){
        return dp[S][v] = 0;
    }

    int res = INF;
    for(int u = 0; u < V; u++){
        if(!(S >> u & 1)){
            res = min(res, rec(S | 1 << u, u) + d[v][u]);
        }
    }
    return dp[S][v] = res;
}

signed main() {
    cin >> V >> E;
    memset(dp,-1,sizeof(dp));

    rep(i,MAX_V) rep(j,MAX_V) d[i][j] = INF;
    for (int i = 0; i < E; i++) {
        int a,b,c;
        cin >> a >> b >> c;
        d[a][b] = c;
    }
    int ans = rec(0,0);
    if(ans == INF) ans = -1;
    cout << ans << endl;
}
