n, m = map(int, input().split()) V = [[0, 0, []] for _ in range(n)] for _ in range(m): s, t, d = map(int, input().split()) V[s-1][2].append((t-1, d)) V[t-1][2].append((s-1, d)) q = [] for v, d in V[0][2]: q.append((v, d, 1)) while len(q) > 0: v, d, n = q.pop(0) if V[v][0] < d: V[v][0] = d V[v][1] = n elif V[v][0] == d and V[v][1] > n: V[v][0] = n elif v != 0: continue for i, w in V[v][2]: if i != 0: q.append((i, min(d, w), n + 1)) print(V[n-1][0], V[n-1][1])