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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author beginner1010
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE2 solver = new TaskE2();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE2 {
        int[] height;
        int[] parent;
        ArrayList<Integer>[] adj;
        ArrayList<Integer>[] weight;
        int[] depth;
        int[][] P;
        int[][] maxWeight;
        int log;

        int find(int x) {
            if (parent[x] == x) return x;
            return find(parent[x]);
        }

        boolean join(int a, int b) {
            a = find(a);
            b = find(b);
            if (a == b) {
                return false;
            }
            if (height[a] > height[b]) {
                parent[b] = a;
            } else {
                parent[a] = b;
                if (height[a] == height[b]) height[b]++;
            }
            return true;
        }

        void setup(int n) {
            Arrays.fill(height, 0);
            for (int i = 0; i < n; i++) {
                parent[i] = i;
            }
        }

        void dfs(int node, int curParent, int d, int curWeight) {
            P[0][node] = curParent; // initialization for DP
            maxWeight[0][node] = curWeight; // initialization for DP
            depth[node] = d;
            for (int i = 0; i < adj[node].size(); i++) {
                int neighbor = adj[node].get(i);
                if (neighbor == curParent)
                    continue;
                dfs(neighbor, node, d + 1, weight[node].get(i));
            }
        }

        int query(int p, int q) {
            if (depth[p] < depth[q]) {
                return query(q, p);
            }
            int res = 0;
            for (int j = log - 1; j >= 0; j--) {
                if (depth[p] - (1 << j) >= depth[q]) {
                    res = Math.max(res, maxWeight[j][p]);
                    p = P[j][p];
                }
            }
            if (p == q) {
                return res;
            }
            for (int j = log - 1; j >= 0; j--) {
                if (P[j][p] != -1 && P[j][p] != P[j][q]) {
                    res = Math.max(res, maxWeight[j][p]);
                    p = P[j][p];
                    res = Math.max(res, maxWeight[j][q]);
                    q = P[j][q];
                }
            }
            res = Math.max(res, maxWeight[0][p]);
            res = Math.max(res, maxWeight[0][q]);
            return res;
        }

        void setupLCA(int n, int m, int[][] edges, boolean[] used) {
            for (log = 0; (1 << log) <= n; log++) ;
            P = new int[log][n];
            maxWeight = new int[log][n];

            for (int[] aux : P)
                Arrays.fill(aux, -1);
            for (int[] aux : maxWeight)
                Arrays.fill(aux, -1);

            adj = new ArrayList[n];
            weight = new ArrayList[n];
            depth = new int[n];
            for (int i = 0; i < n; i++) {
                adj[i] = new ArrayList<>();
                weight[i] = new ArrayList<>();
            }
            for (int i = 0; i < m; i++) { // build the graph/tree
                int a = edges[i][0];
                int b = edges[i][1];
                if (used[edges[i][3]] == false)
                    continue;
                adj[a].add(b);
                weight[a].add(edges[i][2]);
                adj[b].add(a);
                weight[b].add(edges[i][2]);
            }

            dfs(0, 0, 0, -1);

            for (int j = 1; j < log; j++) {
                for (int i = 0; i < n; i++) {
                    P[j][i] = P[j - 1][P[j - 1][i]];
                    maxWeight[j][i] = Math.max(maxWeight[j - 1][P[j - 1][i]], maxWeight[j - 1][i]); // max of i to 2^(j - 1) and parent in 2^(j - 1) to 2^j
                }
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            if (m == n - 1)
                return;

            int[][] edges = new int[m][4];
            for (int i = 0; i < m; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                int c = in.nextInt();
                edges[i] = new int[]{a, b, c, i};
            }

            Arrays.sort(edges, new Comparator<int[]>() {

                public int compare(int[] a, int[] b) {
                    return a[2] < b[2] ? -1 : 1;
                }
            });

            height = new int[n];
            parent = new int[n];

            setup(n);
            boolean[] used = new boolean[m];
            for (int i = 0; i < m; i++) {
                int a = edges[i][0];
                int b = edges[i][1];
                if (join(a, b) == true) {
                    used[edges[i][3]] = true;
                }
            }

            setupLCA(n, m, edges, used);

            ArrayList<Integer[]> ans = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                int idx = edges[i][3];
                if (used[idx] == false) {
                    int a = edges[i][0];
                    int b = edges[i][1];
                    ans.add(new Integer[]{idx, query(a, b)});
                }
            }

            Collections.sort(ans, new Comparator<Integer[]>() {

                public int compare(Integer[] o1, Integer[] o2) {
                    return o1[0] < o2[0] ? -1 : 1;
                }
            });

            for (Integer[] edgeCost : ans) {
                out.println(edgeCost[1]);
            }


        }

    }

    static class InputReader {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputStream stream;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isWhitespace(c));
            return res * sgn;
        }

    }
}