// INOI1402
#include <iostream>
//#include <limits>
using namespace std;
unsigned long computemaxcost(unsigned long arr[][231],unsigned long c, unsigned long int f);
unsigned long selectminburntime(unsigned long [], unsigned long[], unsigned long);
int main()
{
unsigned long c,f;
cin>>c>>f;
unsigned long arr[231][231];
for(unsigned long i = 1; i<= c; i++)
for(unsigned long j = 1; j<=c; j++)
arr[i][j] = 0;
unsigned long k,l;
for(unsigned long i = 1; i<=f; i++)
{
cin>>k>>l;
cin>>arr[k][l];
arr[l][k] = arr[k][l];
}
unsigned long max = computemaxcost(arr,c,f);
cout<<max;
return 0;
}
unsigned long computemaxcost(unsigned long arr[231][231], unsigned long int c,unsigned long f)
{
unsigned long expectedburntime[231];
unsigned long burnt[231];
unsigned long max = 0, k = 1;
while(k<=c){
for(unsigned long i = 1; i<=c; i++)
{
burnt[i] = 0;
expectedburntime[i] = 100002;
}
expectedburntime[k] = 0;
unsigned long i = selectminburntime(burnt,expectedburntime,c);
while(i)
{
burnt[i] = 1;
for(unsigned long j = 1; j<= c; j++)
{
if(arr[i][j] != 0 && burnt[j]!=1 && expectedburntime[i]+arr[i][j] < expectedburntime[j])
{
expectedburntime[j] = expectedburntime[i]+arr[i][j];
}
}
i = selectminburntime(burnt,expectedburntime,c);
}
for(unsigned long ip = 1; ip<=c; ip++)
{
if(expectedburntime[ip]>max)
{
max = expectedburntime[ip];
}
}
k++;
}
return max;
}
unsigned long selectminburntime(unsigned long burnt[], unsigned long expectedburntime[],unsigned long c)
{
unsigned long pos = 0;
unsigned long minburn = 32767;
for(unsigned long i = 1; i<=c; i++)
{
if((!burnt[i]) && (expectedburntime[i] < minburn))
{
minburn = expectedburntime[i];
pos = i;
}
}
return pos;
}