# Python ACになってほしい from collections import deque import sys input = sys.stdin.readline class DSU: def __init__(self, N: int) -> None: self.par = list(range(N)) self.sz = [1] * N def find(self, x: int) -> int: if self.par[x] != x: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x: int, y: int) -> bool: x, y = self.find(x), self.find(y) if x == y: return False if self.sz[x] < self.sz[y]: x, y = y, x self.par[y] = x self.sz[x] += self.sz[y] return True def same(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def main(): N, M = map(int, input().split()) uf = DSU(N) edges = [] for _ in range(M): s, t, w = map(int, input().split()) edges.append((w, s - 1, t - 1)) edges.sort(reverse=True) ret = 1 << 30 for w, u, v in edges: if uf.same(0, N - 1): break ret = w uf.unite(u, v) to = [[] for _ in range(N)] for w, s, t in edges: if w >= ret: to[s].append(t), to[t].append(s) dist = [1 << 30] * N dist[0] = 0 q = deque([0]) while q: now = q.popleft() for nxt in to[now]: if dist[nxt] > dist[now] + 1: dist[nxt] = dist[now] + 1 q.append(nxt) print(ret, dist[N - 1]) if __name__ == '__main__': main()