#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int v,e;
	cin>>v>>e;
	vvi cost(v,vi(v,inf));
	while(e--){
		int a,b,c;
		cin>>a>>b>>c;
		cost[a][b]=c;
	}
	vvi dp(1<<v,vi(v,inf));
	dp[(1<<v)-1][0]=0;
	for(int i=(1<<v)-2;i>=0;i--){
		rep(j,v){
			rep(k,v){
				if(!(i>>k&1))
					dp[i][j]=min(dp[i][j],dp[i|(1<<k)][k]+cost[j][k]);
			}
		}
	}
	if(dp[0][0]==inf)cout<<-1<<endl;
	else cout<<dp[0][0]<<endl;
}