#include <bits/stdc++.h>
#define INF 100000000
using namespace std;

int main()
{
	int V, E;
	cin >> V >> E;
	vector<vector<int>> dp(1 << V, vector<int>(V, INF)), edge(V,vector<int>(V, INF));
	for (int i = 0, s, t, d; i < E; i++) {
		cin >> s >> t >> d;
		edge[s][t] = d;
	}
	dp[0][0] = 0;
	for (int i = 1; i < (1 << V); i++) {
		for (int j = 0; j < V; j++) {
			if (i & (1 << j)) {
				for (int k = 0; k < V; k++) {
					dp[i][j] = min(dp[i][j], dp[i - (1 << j)][k] + edge[k][j]);
				}
			}
		}
	}
	if (dp[(1 << V) - 1][0] == INF)
		cout << -1 << endl;
	else
		cout << dp[(1 << V) - 1][0] << endl;
	return 0;
}