import java.io.*;
import java.util.*;

public class kruskal {
    static class Edge implements Comparable<Edge> {
        public int start;
        public int end;
        public int weight;

        Edge(int start, int end, int weight) {
            this.start = start;
            this.end = end;
            this.weight = weight;
        }

        @Override
        public int compareTo(kruskal.Edge o) {
            return Integer.compare(this.weight, o.weight);
        }
    }

    public static void main(String args[]) throws NumberFormatException, IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int vertexCount = Integer.parseInt(reader.readLine());
        int edgeCount = Integer.parseInt(reader.readLine());

        ArrayList<Edge> edges = new ArrayList<>();

        for (int i = 0; i < edgeCount; i++) {
            String[] tokens = reader.readLine().split(" ");
            int start = Integer.parseInt(tokens[0]);
            int end = Integer.parseInt(tokens[1]);
            int weight = Integer.parseInt(tokens[2]);

            edges.add(new Edge(start, end, weight));
        }

        int[] parents = new int[vertexCount];
        for (int i = 0; i < vertexCount; i++) {
            parents[i] = i;
        }
    
        Collections.sort(edges);

        int min = 0;
    
        for (Edge edge : edges) {
            int firstRoot = findRoot(edge.start, parents);
            int secondRoot = findRoot(edge.end, parents);
    
            if(firstRoot != secondRoot) {
                parents[firstRoot] = secondRoot;
                min = edge.weight;
            }
        }
    
        System.out.println(min + 1);
    }

    public static int findRoot(int node, int[] parents) {
        while (node != parents[node]) {
            node = parents[node];
        }

        return node;
    }
}