For a given weighted directed graph G(V, E), find the distance of the shortest route that meets the following criteria:    * It is a closed cycle where it ends at the same point it starts.   * It visits each vertex exactly once.
def dfs(g, last, vs, first):
    if vs:return min(g[last][v] + dfs(g, v, vs - {v}, first) for v in vs)
    else:return g[last][first]

from sys import stdin
from collections import defaultdict
from math import isinf

readline = stdin.readline

v, e = map(int, readline().split())
g = [[float('inf')] * v for _ in range(v)]
for _ in range(e):
    s, t, d = map(int, readline().split())
    g[s][t] = d

cost = []
vs = set(range(v))
second = 0
for first in range(1, v - 1):
    if isinf(g[first][second]):continue
    for third in range(first + 1, v):
        if isinf(g[second][third]):continue
        cost.append(g[first][second] + g[second][third] + dfs(g, third, vs - {first,second,third}, first))
        
print(min(cost) if cost else -1)


def memoize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func

@memoize
def tsp(p, v):
    if (1 << point_size) - 1 == v:
        return distance_table[p][0]
    else:
        return min(distance_table[p][x] + tsp(x, v | (1 << x)) for x in range(point_size) if not (v & (1 << x)))

from sys import stdin
from collections import defaultdict
from math import isinf

readline = stdin.readline

point_size, e = map(int, readline().split())
distance_table = [[float('inf')] * point_size for _ in range(point_size)]
for _ in range(e):
    s, t, d = map(int, readline().split())
    distance_table[s][t] = d
ans = tsp(0,1)
print(-1 if isinf(ans) else ans)