Problem: After a successful field test, Heidi is considering deploying a trap along some Corridor, possibly not the first one. She wants to avoid meeting the Daleks inside the Time Vortex, so for abundance of caution she considers placing the traps only along those Corridors that are not going to be used according to the current Daleks' plan – which is to use a minimum spanning tree of Corridors. Heidi knows that all energy requirements for different Corridors are now different, and that the Daleks have a single unique plan which they are intending to use.

Your task is to calculate the number E_{max}(c), which is defined in the same way as in the easy version – i.e., the largest e ≤ 10^9 such that if we changed the energy of corridor c to e, the Daleks might use it – but now for every corridor that Heidi considers. 

Input

The first line: number n of destinations, number m of Time Corridors (2 ≤ n ≤ 10^5, n - 1 ≤ m ≤ 10^6). The next m lines: destinations a, b and energy e (1 ≤ a, b ≤ n, a ≠ b, 0 ≤ e ≤ 10^9).

No pair \\{a, b\} will repeat. The graph is guaranteed to be connected. All energy requirements e are distinct.

Output

Output m-(n-1) lines, each containing one integer: E_{max}(c_i) for the i-th Corridor c_i from the input that is not part of the current Daleks' plan (minimum spanning tree).

Example

Input

3 3
1 2 8
2 3 3
3 1 4


Output

4

Note

If m = n-1, then you need not output anything.

Solution (in JAVA):

Solution:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class e2 {
    static int[][] jump;
    static int[][] max;
    static int[] pre;
    static int[] post;
    static ArrayList<Edge>[] adj;
    static int next;
    
    public static void main(String[] args) {
        FS in = new FS(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        int n = in.nextInt();
        int m = in.nextInt();
        
        adj = new ArrayList[n];
        jump  = new int[21][n];
        max = new int[21][n];
        pre = new int[n];
        post = new int[n];
        boolean[] used = new boolean[m];
        Edge[] edges = new Edge[m];
        PriorityQueue<Edge> q = new PriorityQueue<Edge>((Edge a, Edge b) -> a.e-b.e);
        
        for(int i = 0; i < n; i++) {
            adj[i] = new ArrayList<>();
        }
        DisjointSet set = new DisjointSet(n);
        
        for(int i = 0; i < m; i++) {
            edges[i] = new Edge(in.nextInt()-1, in.nextInt()-1, in.nextInt(), i);
            q.add(edges[i]);
        }
        
        while(!q.isEmpty()) {
            Edge curr = q.poll();
            used[curr.id] = set.union(curr.u, curr.v);
            if(used[curr.id]) {
                adj[curr.u].add(curr);
                adj[curr.v].add(new Edge(curr.v, curr.u, curr.e, curr.id));
            }
        }
        dfs(0);
        jump[0][0] = -1;
        for(int i = 1; i <= 20; i++) {
            for(int j = 0; j < n; j++) {
                if(jump[i-1][j] == -1 || jump[i-1][jump[i-1][j]] == -1) {
                    jump[i][j] = -1;
                    continue;
                }
                jump[i][j] = jump[i-1][jump[i-1][j]];
                max[i][j] = Math.max(max[i-1][j], max[i-1][jump[i-1][j]]);
            }
        }
        for(int i = 0; i < m; i++) {
            if(used[i]) continue;
            out.println(lca(edges[i].u, edges[i].v));
        }
        out.close();
    }
    
    static int dfs(int node) {
        pre[node] = next;
        post[node] = next;
        next++;
        for(Edge a : adj[node]) {
            if(jump[0][node] == a.v) continue;
            jump[0][a.v] = node;
            max[0][a.v] = a.e;
            post[node] = dfs(a.v);
        }
        return post[node];
    }
  
    static int lca(int a, int b) {
        if(a == b) return 0;
        if(isPar(a, b)) return lca(b, a);
        int res = 0;
        for(int i = 20; i >= 0; i--) {
            int tmp = jump[i][a];
            if(!isPar(tmp, b)) {
                res = Math.max(res, max[i][a]);
                a = tmp;
            }
        }
        res = Math.max(res, max[0][a]);
        return Math.max(res, lca(b, jump[0][a]));
    }
    
    static boolean isPar(int a, int b) {
        if(a == -1 || b == -1) return true;
        return pre[b] >= pre[a] && pre[a] <= post[b];
    }
    
    static class Edge {
        int u, v, e, id;
        
        public Edge(int U, int V, int E, int I) {
            u = U;
            v = V;
            e = E;
            id = I;
        }
    }
    
    static class DisjointSet {

        int[] s;

        public DisjointSet(int n) {
            Arrays.fill(s = new int[n], -1);
        }

        public int find(int i) {
            return s[i] < 0 ? i : (s[i] = find(s[i]));
        }

        public boolean union(int a, int b) {
            if ((a = find(a)) == (b = find(b))) {
                return false;
            }
            if (s[a] == s[b]) {
                s[a]--;
            }
            if (s[a] <= s[b]) {
                s[b] = a;
            } else {
                s[a] = b;
            }
            return true;
        }
    }
    
    static class FS {

        BufferedReader in;
        StringTokenizer token;
        
        public FS(InputStream str) {
            in = new BufferedReader(new InputStreamReader(str));
        }
        
        public String next() {
            if (token == null || !token.hasMoreElements()) {
                try {
                    token = new StringTokenizer(in.readLine());
                } catch (IOException ex) {
                }
                return next();
            }
            return token.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}