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 int N = 1e5 + 1;
int fa[N][18], mx[N][18], deep[N];
struct node {
  int x, y, z, id;
} a[N * 10];
int n, m;
int faa[N], ans[N * 10];
vector<pair<int, int> > g[N];
int getfa(int x) { return x == faa[x] ? x : faa[x] = getfa(faa[x]); }
void dfs(int x) {
  for (int i = 0; fa[fa[x][i]][i]; i++)
    fa[x][i + 1] = fa[fa[x][i]][i],
              mx[x][i + 1] = max(mx[x][i], mx[fa[x][i]][i]);
  deep[x]++;
  for (auto u : g[x])
    if (u.first != fa[x][0]) {
      fa[u.first][0] = x;
      mx[u.first][0] = u.second;
      deep[u.first] = deep[x];
      dfs(u.first);
    }
}
int getlca(int x, int y) {
  if (deep[x] < deep[y]) swap(x, y);
  int i = 17;
  while (deep[x] != deep[y]) {
    while (deep[fa[x][i]] < deep[y]) i--;
    x = fa[x][i];
  }
  i = 17;
  while (x != y) {
    while (i && fa[x][i] == fa[y][i]) i--;
    x = fa[x][i], y = fa[y][i];
  }
  return x;
}
int up(int x, int step) {
  int i = 17;
  while (step) {
    while ((1 << i) > step) i--;
    step -= (1 << i);
    x = fa[x][i];
  }
  return x;
}
int get(int x, int fa) {
  int y = 0, dis = deep[x] - deep[fa];
  while ((1 << (y + 1)) <= dis) y++;
  int z = up(x, dis - (1 << y));
  return max(mx[x][y], mx[z][y]);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].z);
    a[i].id = i;
  }
  for (int i = 1; i <= n; i++) faa[i] = i;
  sort(a + 1, a + m + 1, [](node a, node b) { return a.z < b.z; });
  for (int i = 1; i <= m; i++) {
    int x = getfa(a[i].x), y = getfa(a[i].y);
    if (x != y) {
      g[a[i].x].push_back(make_pair(a[i].y, a[i].z));
      g[a[i].y].push_back(make_pair(a[i].x, a[i].z));
      faa[x] = y;
      a[i].id = 0;
    }
  }
  dfs(1);
  for (int i = 1; i <= m; i++)
    if (a[i].id) {
      int x = a[i].x, y = a[i].y;
      int fa = getlca(x, y);
      int v = 0;
      if (fa != x) {
        v = max(get(x, fa), v);
      }
      if (fa != y) {
        v = max(get(y, fa), v);
      }
      ans[a[i].id] = v + 1;
    }
  for (int i = 1; i <= m; i++)
    if (ans[i]) printf("%d\n", ans[i] - 1);
  return 0;
}