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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const ll MAXV = 17;

ll dist[MAXV][MAXV]{};
ll dp[(1ll<<MAXV)][MAXV]{};

int main(int argc, char **argv)
{
	ll V, E;
	cin >> V >> E;
	REP(i, V)REP(j, V) dist[i][j] = INF;
	REP(i, E)
	{
		ll a, b, d; cin >> a >> b >> d;;
		dist[a][b] = d;
	}

	ll SMAX = (1ll<<V);
	REP(bits, SMAX) REP(v, V) dp[bits][v] = INF;
	dp[0][0] = 0;

	REP(bits, SMAX)
	{
		REP(s, V)
		{
			REP(g, V)
			{
				// s to g
				if (!(bits & (1ll<<g)))
				{
					ll tmp = bits|(1ll<<g);
					dp[tmp][g] = min(dp[tmp][g],
									 dp[bits][s]+dist[s][g]);
				}
			}
		}
	}

	ll res = dp[SMAX-1][0];
	std::cout << (res == INF ? -1 : res)<< std::endl;
}

