import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); ArrayList> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new HashMap<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; int c = sc.nextInt(); if (!graph.get(a).containsKey(b) || graph.get(a).get(b) < c) { graph.get(a).put(b, c); graph.get(b).put(a, c); } } PriorityQueue queue = new PriorityQueue<>(); int[] costs = new int[n]; int max = 0; for (int i = 0; i < n; i++) { queue.add(new Path(i, 0)); getCost(costs, queue, graph); for (int x : costs) { max = Math.max(max, x); } } System.out.println(max); } static void getCost(int[] costs, PriorityQueue queue, ArrayList> graph) { Arrays.fill(costs, -1); boolean[] used = new boolean[costs.length]; while (queue.size() > 0) { Path p = queue.poll(); if (used[p.idx]) { continue; } used[p.idx] = true; costs[p.idx] = p.value; for (int x : graph.get(p.idx).keySet()) { queue.add(new Path(x, p.value + graph.get(p.idx).get(x))); } } } static class Path implements Comparable { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return another.value - value; } } }