import collections import heapq import math N,M=map(int,input().split()) G = collections.defaultdict(list) for _ in range(M): S,T,D = map(int, input().split()) G[S-1].append((T-1,D)) G[T-1].append((S-1,D)) def dijkstra(): weights = [-math.inf for _ in range(N)] que = [] heapq.heapify(que) heapq.heappush(que, (math.inf, 0)) # weight, index nums = [0]*N while que: ''' aw: accumlated weight nw: next weight ''' aw, i = heapq.heappop(que) if weights[i] and aw <= weights[i]: continue weights[i] = aw for j, nw in G[i]: nw = min(aw, nw) heapq.heappush(que, (nw, j)) ans = weights[N-1] return ans def bfs(max_w): que = collections.deque([(0,0)]) # index, something val visited = [-1]*N while que: i, c = que.popleft() # queはFIFO if visited[i] >= 0: continue visited[i] = c for j, d in G[i]: if visited[j] == -1 and max_w <= d: # まだ未踏のノードであれば que.append((j,c+1)) # 自分の値に+1してqueに入れる return visited[-1] max_w = dijkstra() min_p = bfs(max_w) print(max_w, min_p)