1 #include<cstdio>
2
3 #include<cstdlib>
4
5 #include<cmath>
6
7 #include<cstring>
8
9 #include<algorithm>
10
11 #include<iostream>
12
13 #include<vector>
14
15 #include<map>
16
17 #include<set>
18
19 #include<queue>
20
21 #include<string>
22
23 #define inf 1000000000
24
25 #define maxn 19*(1<<19)
26
27 #define maxm 500+100
28
29 #define eps 1e-10
30
31 #define ll long long
32
33 #define for0(i,n) for(int i=0;i<=(n);i++)
34
35 #define for1(i,n) for(int i=1;i<=(n);i++)
36
37 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
38
39 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
40
41 #define mod 1000000007
42
43 using namespace std;
44
45 inline int read()
46
47 {
48
49 int x=0,f=1;char ch=getchar();
50
51 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
52
53 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
54
55 return x*f;
56
57 }
58 int d[19][1<<19],g[20][20],n,m;
59 struct rec{int x,y;}q[maxn+1];
60 bool v[19][1<<19],vv[1<<19];
61 inline void spfa()
62 {
63 for0(i,n)for0(j,(1<<n)-1)d[i][j]=inf;
64 d[1][1]=0;
65 int l=0,r=1;q[1].x=1,q[1].y=1;
66 while(l<r)
67 {
68 int x=q[++l].x,y=q[l].y;v[x][y]=0;if(l==maxn)l=0;
69 for1(i,n)
70 if(i!=x&&g[x][i])
71 {
72 int yy=y|(1<<(i-1));
73 if(d[x][y]+g[x][i]<d[i][yy])
74 {
75 d[i][yy]=d[x][y]+g[x][i];
76 if(!v[i][yy])
77 {
78 v[i][yy]=1;
79 q[++r].x=i;
80 q[r].y=yy;
81 if(r==maxn)r=0;
82 }
83 }
84 }
85 }
86 //for1(i,n)for0(j,(1<<n)-1)cout<<i<<‘ ‘<<j<<‘ ‘<<d[i][j]<<endl;
87 }
88 inline void dfs(int x)
89 {
90 if(vv[x])return;
91 vv[x]=1;
92 for1(i,n)d[0][x]=min(d[0][x],d[i][x]);
93 for1(i,n)
94 if(!(x&(1<<(i-1))))
95 {
96 int y=x|(1<<(i-1));
97 dfs(y);;
98 if(d[0][x]>d[0][y])d[0][x]=d[0][y];
99 }
100 }
101
102 int main()
103
104 {
105
106 //freopen("input.txt","r",stdin);
107
108 //freopen("output.txt","w",stdout);
109
110 n=read();m=read();
111 for1(i,m){int x=read(),y=read(),z=read();g[x][y]=z;g[y][x]=z;}
112 spfa();
113 dfs(0);
114 int ans=inf;
115 for0(i,(1<<n)-1)ans=min(ans,max(d[0][i],d[0][(1<<n)-1-i]));
116 printf("%d\n",ans);
117
118 return 0;
119
120 }