#include<bits/stdc++.h>

using namespace std;

inline int read() {
	int res=0,fh=1;
	char ch=getchar();
	while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
	if(ch=='-')fh=-1,ch=getchar();
	while(ch>='0'&&ch<='9')res=res*10+ch-'0',ch=getchar();
	return fh*res;
}

const int maxn=16;
int n,m,mxs,sum[(1<<16)+12],a[maxn][maxn];
int f[(1<<maxn)][maxn];
inline int Max(int a,int b){return a>b?a:b;}

int main(){
	n=read(),m=read();
	mxs=(1<<n)-1;
	for(int i=1;i<=m;i++){
		int x=read()-1,y=read()-1,z=read();
		a[x][y]=a[y][x]=z;
	}
	for(int i=0;i<=mxs;i++){
		sum[i]=0;
		for(int j=0;j<n;j++)
			if((i&(1<<j)))
				for(int k=j+1;k<n;k++)
					if((i&(1<<k))) sum[i]+=a[j][k];
	}
	memset(f,-1,sizeof f);
	f[1][0]=0;
	for(int i=1;i<=mxs;i+=2){
		for(int j=0;j<n;j++){
			if(f[i][j]==-1) continue;
			if(!(i&(1<<j))) continue;
			for(int k=0;k<n;k++)
				if(a[j][k]&&(!(i&(1<<k))))
					f[i|(1<<k)][k]=Max(f[i|(1<<k)][k],f[i][j]+a[j][k]);
			int c=(mxs-i)|(1<<j);
			for(int k=c;k>=0;k=(k==0?-1:(k-1)&c))
				f[i|k][j]=Max(f[i][j]+sum[k],f[i|k][j]);
		}
	}
	int ans=0;
	for(int i=(mxs>>1)+2;i<=mxs;i+=2)
		ans=Max(ans,f[i][n-1]);
	printf("%d\n",sum[mxs]-ans);
	return 0;
}

#include <stdio.h>
#include <vector>
#include <set>
#include <utility>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, l, n, m, a, b, now, min;
  scanf("%lld%lld", &n, &m);
  vector<ll> vec[n], rev[n];
  ll d[n], be[n];
  pair<ll, ll> p;
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld", &a, &b);
    vec[--a].push_back(--b);
    rev[b].push_back(a);
  }
  for(i = 0; i < n; ++i) {
    set< pair<ll, ll> > s;
    for(j = 0; j < n; ++j) d[j] = 1e9;
    d[i] = 0;
    for(j = 0; j < n; ++j) s.insert(make_pair(d[j], j));
    while(s.size()) {
      p = *s.begin(), s.erase(s.begin());
      if(p.first == 1e9) break;
      for(j = 0; j < vec[p.second].size(); ++j) if(d[vec[p.second][j]] > p.first + 1) {
        s.erase(make_pair(d[vec[p.second][j]], vec[p.second][j]));
        d[vec[p.second][j]] = p.first + 1;
        be[vec[p.second][j]] = p.second;
        s.insert(make_pair(p.first + 1, vec[p.second][j]));
      }
    }
    for(j = 0; j < rev[i].size(); ++j) if(d[rev[i][j]] != 1e9) {
      vector<ll> ans;
      now = rev[i][j];
      while(now != i) ans.push_back(now), now = be[now];
      ans.push_back(i);
      min = ans.size();
      ll flg[n];
      for(k = 0; k < n; ++k) flg[k] = ans.size();
      flg[i] = ans.size() - 1;
      for(now = ans.size() - 2; now >= 0; --now) {
        for(k = 0; k < vec[ans[now]].size(); ++k) if(flg[vec[ans[now]][k]] < min) min = flg[vec[ans[now]][k]];
        if(min != ans.size()) break;
        flg[ans[now]] = now;
      }
      printf("%lld\n", min - now + 1);
      for(k = min; k >= now; --k) printf("%lld\n", ans[k] + 1);
      return 0;
    }
  }
  printf("-1");
  return 0;
}