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.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
 
 
public class q5 {
	static HashMap<Integer,Integer>[] adj;
	static int[][] par, min;
	static int[] depth;
	static int d;
	static int ans;
	
	static void dfs(int x, int p) {
		for(int j:adj[x].keySet()) {
			if(j!=p) {
				par[0][j]=x;
				min[0][j]=adj[x].get(j);
				depth[j]=depth[x]+1;
				dfs(j,x);
			}
		}
	}
	static int walk(int i, int steps) {
        for(int k=0;k<=d && i!=-1;k++) {
            if(((1<<k)&steps)>0) {
            	ans=Math.max(ans, min[k][i]);
            	//int a=ans;
                i=par[k][i];
            }
        }
        return i;
    }
    
    static int lca(int i, int j) {
        if(depth[i]>depth[j]) {
            i=walk(i,depth[i]-depth[j]);
        }
        else if(depth[j]>depth[i]) j=walk(j,depth[j]-depth[i]);
        
        if(i==j) return i;
        //if(i==-1 || j==-1) return 0;
        for(int k=d;k>=0;k--) {
            if(par[k][i]!=par[k][j]) {
            	ans=Math.max(ans,min[k][i]);
            	ans=Math.max(ans, min[k][j]);
                i=par[k][i];
                j=par[k][j];
            }
        }
        ans=Math.max(ans, min[0][i]);
        ans=Math.max(ans, min[0][j]);
        return par[0][i];
    }
	
 
	public static void main(String[] args) throws IOException {
		
	Reader.init(System.in);
	PrintWriter out=new PrintWriter(System.out);
	int n=Reader.nextInt();
	int m=Reader.nextInt();
	adj=new HashMap[n];
	d=Integer.numberOfTrailingZeros(Integer.highestOneBit(n));
	par=new int[d+1][n];min=new int[d+1][n];
	for(int i=0;i<=d;i++) Arrays.fill(par[i],-1);
	depth=new int[n];
	for(int i=0;i<n;i++) adj[i]=new HashMap<Integer,Integer>();
	int[] included=new int[m];
	NoD[] arr=new NoD[m];
	NoD[] arr2=new NoD[m];
	for(int i=0;i<m;i++) {
		NoD c=new NoD(Reader.nextInt(),Reader.nextInt(),Reader.nextInt(),i);
		arr[i]=c;
		arr2[i]=c;
	}
	
	//int low=0,high=(int)1e9;
	Arrays.sort(arr,new Comparator<NoD>() {
			public int compare(NoD a,NoD b) {
				return a.z-b.z;
			}
	});
		
	DisJoint set=new DisJoint(n);
	for(NoD c:arr) {
		if(set.find(c.x)!=set.find(c.y)) {
				set.union(c.x, c.y);
				included[c.i]=1;
				adj[c.x-1].put(c.y-1, c.z);
				adj[c.y-1].put(c.x-1, c.z);
		}
	}
	dfs(0,-1);
	for(int i=1;i<=d;i++) {
		for(int j=0;j<n;j++) {
			int mid=par[i-1][j];
			if(mid!=-1) {
				par[i][j]=par[i-1][mid];
				min[i][j]=Math.max(min[i-1][mid], min[i-1][j]);
			}
		}
	}
	for(int i=0;i<m;i++) {
		if(included[i]==0) {
			//HashMap<Integer,Integer>[] a2=adj;
			ans=Integer.MIN_VALUE;
			int a=arr2[i].x,b=arr2[i].y;
			a--;b--;
			lca(a,b);
			out.println(ans);
		}
	}
	
	
	
	
	
	out.flush();
		
	}
}
 
class NoD{
	int x,y,z,i;
	NoD(int a,int b,int c,int d){
		x=a;y=b;z=c;i=d;
	}
}
 
class DisJoint {
	int[] arr;
	int[] parent;
	int[] rank;
	DisJoint(int n){
		arr=new int[n+1];
		parent=new int[n+1];
		rank=new int[n+1];
		for(int i=1;i<=n;i++) {
			arr[i]=i;
			parent[i]=i;
			rank[i]=0;
		}
	}
 
	int find(int value) {
		int par=parent[value];
		if(par==value)
			return par;
		parent[value]=find(par);
		return parent[value];
	}
	
	void union(int data1,int data2) {
		int parent1=find(data1);
		int parent2=find(data2);
		if(parent1!=parent2) {
			if(rank[parent1]>=rank[parent2]) {
				parent[parent2]=parent1;
				if(rank[parent1]==rank[parent2])
					rank[parent1]++;
			}
			else {
				parent[parent1]=parent2;
			}
		}
		
	}
}

 
 
 
 
 
 
 
 
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    /** call this method to initialize reader for InputStream */
    static void init() throws IOException {
    	 reader = new BufferedReader(
                 new FileReader("pattern.in") );
    tokenizer = new StringTokenizer("");
    }
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}