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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double Pi = 3.1415926535897932;
const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};
const int maxn = 1e5 + 5;
const int maxe = 1e6 + 5;
int n, m;
int head[maxn];
int ver[maxe], edge[maxe], nex[maxe];
int pn = 1;
int f[maxn][22];
int g[maxn][22];
int d[maxn];
int ans[maxe];
struct Edge {
  int a, b, w;
  bool vis;
  int pos;
  bool operator<(const Edge &e) const { return w < e.w; }
} edges[maxe];
int uset[maxn];
int find(int x) {
  if (x != uset[x]) uset[x] = find(uset[x]);
  return uset[x];
}
void addedge(int a, int b, int w) {
  ver[++pn] = b;
  edge[pn] = w;
  nex[pn] = head[a];
  head[a] = pn;
  ver[++pn] = a;
  edge[pn] = w;
  nex[pn] = head[b];
  head[b] = pn;
}
void dfs(int a, int fa) {
  for (int i = head[a]; i; i = nex[i]) {
    const int &b = ver[i];
    if (b == fa) continue;
    d[b] = d[a] + 1;
    f[b][0] = a;
    g[b][0] = edge[i];
    dfs(b, a);
  }
}
int lca(int a, int b) {
  if (d[a] < d[b]) swap(a, b);
  int mx = -1;
  for (int i = 20; i >= 0; i--) {
    if (d[a] - d[b] >= (1 << i)) {
      mx = max(mx, g[a][i]);
      a = f[a][i];
    }
  }
  if (a == b) return mx;
  for (int i = 20; i >= 0; i--) {
    if (f[a][i] != f[b][i]) {
      mx = max(mx, g[a][i]);
      mx = max(mx, g[b][i]);
      a = f[a][i];
      b = f[b][i];
    }
  }
  mx = max(mx, g[a][0]);
  mx = max(mx, g[b][0]);
  a = f[a][0];
  b = f[b][0];
  return mx;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    edges[i] = Edge{a, b, w, false, i};
  }
  for (int i = 1; i <= n; i++) uset[i] = i;
  sort(edges + 1, edges + 1 + m);
  for (int i = 1; i <= m; i++) {
    Edge &e = edges[i];
    if (find(e.a) != find(e.b)) {
      e.vis = true;
      uset[find(e.a)] = find(e.b);
      addedge(e.a, e.b, e.w);
    }
  }
  d[1] = 1;
  memset(f, -1, sizeof(f));
  dfs(1, -1);
  for (int i = 1; i <= 20; i++) {
    for (int j = 1; j <= n; j++) {
      if (f[j][i - 1] != -1) {
        g[j][i] = max(g[j][i - 1], g[f[j][i - 1]][i - 1]);
        f[j][i] = f[f[j][i - 1]][i - 1];
      }
    }
  }
  memset(ans, -1, sizeof(ans));
  for (int i = 1; i <= m; i++)
    if (!edges[i].vis) {
      Edge &e = edges[i];
      ans[e.pos] = lca(e.a, e.b);
    }
  for (int i = 1; i <= m; i++)
    if (ans[i] != -1) printf("%d\n", ans[i]);
  return 0;
}