 
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

 
constexpr int gcd(int a,int b){return b?gcd(b,a%b):a;}
constexpr int lcm(int a,int b){return a*b/gcd(a,b);}


int main(){
    dcl(n,m);
    vector<vector<pii>> el(n+1);
    set<pii> used; 
    rep(i,m){
        dcl(a,b,c);
        el[a].eb(b,c);
        el[b].eb(a,c);
    }
    
    
    for(int st=1;st<=n;st++){
        vi ans(n+1,-1);
        ans[0]=0;
        priority_queue<pair<int,pii>, vector<pair<int,pii>>, greater<pair<int,pii>>> que;
        que.emplace(0,mp(st,st));
        while(!que.empty()){
            auto t=que.top();
            que.pop();
            if(ans[t.sc.sc]==-1){
                ans[t.sc.sc]=t.fs;
                if(t.sc.fs!=t.sc.sc){
                    if(t.sc.fs>t.sc.sc){
                        used.emplace(t.sc.sc,t.sc.fs);
                    }else{
                        used.insert(t.sc);
                    }
                }
                for(auto l:el[t.sc.sc]){
                    que.emplace(t.fs+l.sc,mp(t.sc.sc,l.fs));
                }
            }
        }
        //puti(ans);
    }
    //for(auto l:used)cout<<l.fs<<","<<l.sc<<endl;
    //cout<<m-used.size()<<endl;
    cout<<0<<endl;
}
