import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class No1473 { public static void main(String[] args) throws IOException { String[] strings = readStr(); int n = Integer.parseInt(strings[0].split(" ")[0]); int m = Integer.parseInt(strings[1].split(" ")[1]); long[][] std = new long[n+1][m+1]; int[][] sg = new int[n+1][2]; int s = 0 , t = 0; long d = 0; 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(s > t) { int t2 = t; t = s; s = t2; } std[s][t] = Math.max(std[s][t], d); if(sg[s][0] > 0) { sg[s][0] = Math.min(sg[s][0], t); }else { sg[s][0] = t; } sg[s][1] = Math.max(sg[s][1], t); } long[][] ans = new long[n+1][2]; ans[1][0] = (long)Math.pow(10, 9); for(int i = 1;i <= n;i++) { for(int j = sg[i][0];j <= sg[i][1];j++) { if(ans[i][0] == 0 ) { break; } if(std[i][j] > 0 ) { d = ans[j][0]; ans[j][0] = Math.max(ans[j][0], Math.min(ans[i][0], std[i][j])); if(d != ans[j][0] ) { ans[j][1] = ans[i][1] + 1; } } } } System.out.println(ans[n][0] + " " + ans[n][1]); } 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; } }