n, m = gets.split(" ").map{|s| s.to_i} w = Array.new(n) {Array.new(2, -Float::INFINITY)} 0.upto(n-1) {|i| w[i][1] = Float::INFINITY } w[0][0] = Float::INFINITY v = Array.new(n) {Array.new} m.times { s, t, d = gets.split(" ").map{|s| s.to_i} v[s-1] << [t-1, d] v[t-1] << [s-1, d] } que = [[0, Float::INFINITY, 0]] while que.size > 0 do cv, cd, ci = que.shift v[cv].each {|nv, nd| nd = cd if cd < nd if nd > w[nv][0] or (nd == w[nv][0] and ci+1 < w[nv][1]) then w[nv] = [nd, ci+1] que << [nv, nd, ci+1] if nv != n-1 end } end puts "#{w[n-1][0]} #{w[n-1][1]}"