1#include<stdio.h>
2#include<stdlib.h>
3#define INFINITY 1000000001
4
5long N,M;
6long r[2000][2000];
7struct item
8{
9 int v;
10 int lowcost;
11}closeedge[2000];
12
13int Prim(int v)
14{
15 int i,j,w,v0;
16 long min,d[2000];
17 min = INFINITY;
18 for(i=0;i<N;i++)
19 {
20 if(i != v)
21 {
22 closeedge[i].v = v;
23 closeedge[i].lowcost = r[v][i];
24 }
25 d[i] = 0;
26 }
27 closeedge[v].lowcost = 0;
28 for(i = 1;i < N;i++)
29 {
30 min = INFINITY;
31 for(w = 0;w < N; w++)
32 {
33 if(closeedge[w].lowcost>0 && closeedge[w].lowcost<min)
34 {
35 min = closeedge[w].lowcost;
36 v0 = w;
37 }
38 }
39 d[v0] = closeedge[v0].lowcost;
40 closeedge[v0].lowcost = 0;
41 for(j = 0;j<N;j++)
42 {
43 if(r[v0][j] < closeedge[j].lowcost)
44 {
45 closeedge[j].lowcost = r[v0][j];
46 closeedge[j].v = v0;
47 }
48 }
49
50 }
51 min = 0;
52 for(j=0;j<N;j++)
53 {
54 if(d[j]>min)
55 min = d[j];
56 }
57 return min;
58}
59void initialize()
60{
61 int i,j;
62 for(i=0;i<N;i++)
63 for(j=0;j<N;j++)
64 r[i][j] = INFINITY;
65}
66main()
67{
68
69 int i,x,y;
70 long temp;
71 scanf("%ld%ld",&N,&M);
72 //memset(r,INFINITY,sizeof(r));
73 initialize();
74 for(i = 0;i<M;i++)
75 {
76
77 scanf("%d%d%ld",&x,&y,&temp);
78 if(r[x-1][y-1]<INFINITY)
79 {
80 if(r[x-1][y-1]>temp)
81 {
82 r[x-1][y-1] = r[y-1][x-1] = temp;
83
84 }
85 }
86 else
87 {
88 r[x-1][y-1] = r[y-1][x-1] = temp;
89
90 }
91 }
92
93 printf("%ld\n",Prim(0));
94}
95