from heapq import heapify, heappop, heappush from collections import defaultdict n, m = map(int, input().split()) edge = defaultdict(list) for _ in range(m): s, t, d = map(int, input().split()) edge[s].append((t, d)) edge[t].append((s, d)) H = [(-10**18, 0, 1)] heapify(H) while H: w, cnt, cp = heappop(H) w *= -1 if cp == n: print(w, cnt) break for np, nw in edge[cp]: nw = min(nw, w) heappush(H, (-nw, cnt + 1, np))