import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; import java.util.Queue; public class No1473 { static ArrayList[] list; static long[][] std; static int n; public static void main(String[] args) throws IOException { String[] strings = readStr(); n = Integer.parseInt(strings[0].split(" ")[0]); int m = Integer.parseInt(strings[0].split(" ")[1]); std = new long[n+1][m+1]; int s = 0 , t = 0; long d = 0; ArrayList dlist = new ArrayList(); list = new ArrayList[n+1]; ArrayList list0; for(int i = 1;i <= m;i++) { s = Integer.parseInt(strings[i].split(" ")[0]); t = Integer.parseInt(strings[i].split(" ")[1]); d = Long.parseLong((strings[i].split(" ")[2])); if(!dlist.contains(d)) { dlist.add(d); } if(s > t) { int t2 = t; t = s; s = t2; } if(list[s] == null ) { list0 = new ArrayList(); list0.add(t); list[s] = list0; std[s][t] = d; }else if(list[s].contains(t)) { std[s][t] = Math.max(d, std[s][t]); }else { list[s].add(t); list[s].sort(null); std[s][t] = d; } } dlist.sort(Collections.reverseOrder()); int count = 0; long dans = 0; for (long d2 : dlist) { count = dhantei(d2); if(count > 0) { dans = d2; break; } } System.out.println(dans + " " + count); } public static int dhantei(long d) { int[] root = new int[n+1]; Queue queue = new ArrayDeque(); queue.add(1); while(!queue.isEmpty()) { int s = queue.poll(); if(list[s] != null) { for (int t : list[s]) { if(std[s][t] < d) { continue; } if(root[t] == 0) { root[t]= root[s] + 1; }else if(root[s] + 1 < root[t]){ root[t]= root[s] + 1; } queue.add(t); } } } return root[n]; } public static String[] readStr() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ArrayList list = new ArrayList<>(); do { list.add(br.readLine()); }while(br.ready()); br.close(); String[] text = new String[list.size()]; list.toArray(text); return text; } }