#include "bits/stdc++.h" //#define int long long using namespace std; using ll = long long; using P = pair; const ll INF = (1LL << 61); ll mod = 1000000007; signed main() { ios::sync_with_stdio(false); cin.tie(0); ll n, m; cin >> n >> m; vector>>G(n); for (int i = 0; i < m; i++) { ll s, t, d; cin >> s >> t >> d; s--; t--; G[s].push_back({ t, d }); G[t].push_back({ s, d }); } ll l = -1, r = 1001001001001; ll ans = 0; while (r - l > 1) { ll mid = (l + r) / 2; queueq; vectornow(n, -1); q.push(0); now[0] = 0; while (!q.empty()) { ll p = q.front(); q.pop(); for (auto nv : G[p]) { ll to = nv.first, tmp = nv.second; if (tmp < mid)continue; if (now[to] != -1)continue; now[to] = now[p] + 1; q.push(to); } } if (now[n - 1] == -1)r = mid; else { l = mid; ans = now[n - 1]; } } cout << l << " " << ans << endl; return 0; }