#include using namespace std; using ll = long long; using P = pair; #define rep(i, n) for(int i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() int main(){ int n,m; cin >> n >> m; vector> to(n); rep(i,m){ int s,t,d; cin >> s >> t >> d; s--; t--; to[s].push_back(make_pair(t,d)); to[t].push_back(make_pair(s,d)); } int ok = 0, ng = 1000000001, ans; while(ng-ok != 1){ int md = (ng + ok) / 2; vector dist(n,-1); dist[0] = 0; queue que; que.push(0); while(que.size()){ int now = que.front(); que.pop(); for(auto p:to[now]){ int x,w; tie(x,w) = p; if(w < md || dist[x] != -1) continue; dist[x] = dist[now] + 1; que.push(x); } } if(dist[n-1] != -1){ ok = md; ans = dist[n-1]; } else ng = md; } cout << ok << " " << ans << endl; return 0; }