import heapq def dijkstra(G, start=0): n = len(G) dist = [-1] * n Q = [] dist[start] = 0 heapq.heappush(Q, (0, start)) while Q: p = heapq.heappop(Q) v = p[1] d = dist[v] if d < p[0]: continue for nv, nc in G[v]: if dist[nv] == -1 or d + nc < dist[nv]: dist[nv] = d + nc heapq.heappush(Q, (d + nc, nv)) return dist def dijkstra_max(G, start=0): inf = 10**10 n = len(G) dist = [-1] * n Q = [] dist[start] = inf heapq.heappush(Q, (-inf, start)) while Q: p = heapq.heappop(Q) v = p[1] d = dist[v] if d < p[0]: continue for nv, nc in G[v]: if dist[nv] == -1 or min(d, nc) > dist[nv]: dist[nv] = min(d, nc) heapq.heappush(Q, (-min(d, nc), nv)) return dist n, m = map(int, input().split()) G = [[] for _ in range(n)] for _ in range(m): s, t, d = map(int, input().split()) s -= 1 t -= 1 G[s].append((t, d)) G[t].append((s, d)) L = dijkstra_max(G) w = L[n-1] T = [[] for _ in range(n)] for v, g in enumerate(G): for nv, d in g: if w <= d: T[v].append((nv, 1)) ans = dijkstra(T)[n-1] print(w, ans)