// Arup Guha
// 3/30/2024
// Solution to Kattis Problem: Driving Range
// https://open.kattis.com/problems/drivingrange

import java.util.*;
import java.io.*;

public class drivingrange {

	public static int n;
	public static ArrayList<edge>[] graph;
	
	public static void main(String[] args) throws Exception {
	
		FastScanner stdin = new FastScanner(System.in);
		
		n = stdin.nextInt();
		int numE = stdin.nextInt();
			
		// Form the graph.
		graph = new ArrayList[n];
		for (int i=0; i<n; i++) 
			graph[i] = new ArrayList<edge>();
			
		// Add edges.
		for (int i=0; i<numE; i++) {
			int u = stdin.nextInt();
			int v = stdin.nextInt();
			int w = stdin.nextInt();
			graph[u].add(new edge(u, v, w));
			graph[v].add(new edge(v, u, w));
		}
		
		// Call adjusted Prim's.
		int maxEdge = prims(0);
			
		// Ta da!
		if (maxEdge == -1)
			System.out.println("IMPOSSIBLE");
		else
			System.out.println(maxEdge);
	}
	
	// Runs Prim's from vertex startv and returns the weight of max edge of the MST.
	public static int prims(int startv) {
		
		boolean[] used = new boolean[n];
		used[startv] = true;
		int numedges = 0;
		int res = -1;
		PriorityQueue<edge> pq = new PriorityQueue<edge>();
		
		// Add each edge from the start vertex into the priority queue.
		for (edge e: graph[startv])
			pq.offer(e);
		
		// Loop until we have enough edges.
		while (numedges < n-1) {
			
			// Graph isn't connected.
			if (pq.size() == 0) break;
			
			// Get the next edge.
			edge cur = pq.poll();
			
			// Doesn't get us somewhere new, try again.
			if (used[cur.u] && used[cur.v]) continue;
			
			// Figure out new edge.
			int newv = used[cur.v] ? cur.u : cur.v;
			
			// Mark as true.
			used[newv] = true;
			
			// Add edges leaving newv to the priority queue.
			for (edge e: graph[newv])
				pq.offer(e);
			
			// Update edge count and max edge.
			numedges++;
			res = cur.w;
		}
		
		// Means no mst.
		if (numedges < n-1) return -1;
		
		// This is the mst max edge.
		return res;
	}
}

class edge implements Comparable<edge> {

	public int u;
	public int v;
	public int w;
	
	public edge(int myu, int myv, int myw) {
		u = myu;
		v = myv;
		w = myw;
	}
	
	public int compareTo(edge other) {
		return this.w - other.w;
	}

}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;
	
    public FastScanner(InputStream i) {
        br = new BufferedReader(new InputStreamReader(i));
        st = new StringTokenizer("");
    }
			
    public String next() throws IOException {
        if(st.hasMoreTokens())
            return st.nextToken();
        else
            st = new StringTokenizer(br.readLine());
        return next();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws IOException {
        return Long.parseLong(next());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}