n, m = map(int, input().split()) roads = [[] for _ in range(n)] for i in range(m): s, t, d = map(int, input().split()) s, t = s - 1, t - 1 roads[s].append((t, d)) roads[t].append((s, d)) from collections import deque que = deque([(0, 1000000002)]) log = [(-1,-1) for _ in range(n)] log[0] = (0, 1000000001) while que: cc, cw = que.popleft() if log[cc][1] > cw: continue for nc, nw in roads[cc]: d, w = log[nc] mw = min(cw, nw) if w > mw: continue elif w == mw: if d <= log[cc][0] + 1: continue #重さが同じなら、距離(道の数)が小さい方へ更新 log[nc] = (log[cc][0] + 1, mw) else: #従来の方が軽ければ、重さと距離を更新 log[nc] = (log[cc][0] + 1, mw) que.append((nc, mw)) print(log[n - 1][1], log[n - 1][0])