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 = 100005;
const int M = 1000005;
struct Edge {
  int x, y, v, id;
  bool operator<(const Edge &a) const { return v < a.v; }
} E[M];
struct edge {
  int to, next, v, id;
} e[N * 2];
int head[N], tot;
int fa[N], n, m;
int used[M], ans[M];
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
void add(int x, int y, int v, int id) {
  e[++tot] = (edge){y, head[x], v, id};
  head[x] = tot;
}
int Fa[N][18];
int Fav[N][18];
int Mnv[N][18];
int Faid[N];
int dep[N];
void dfs(int x) {
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != Fa[x][0]) {
      dep[e[i].to] = dep[x] + 1;
      Faid[e[i].to] = e[i].id;
      Fav[e[i].to][0] = e[i].v;
      Fa[e[i].to][0] = x;
      dfs(e[i].to);
    }
}
int Query(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int tmp = dep[x] - dep[y], ans = 0;
  for (int i = (int)(0); i <= (int)(16); i++)
    if (tmp & (1 << i)) ans = max(ans, Fav[x][i]), x = Fa[x][i];
  if (x == y) return ans;
  for (int i = (int)(16); i >= (int)(0); i--)
    if (Fa[x][i] != Fa[y][i]) {
      ans = max(ans, max(Fav[x][i], Fav[y][i]));
      x = Fa[x][i];
      y = Fa[y][i];
    }
  return max(ans, max(Fav[x][0], Fav[y][0]));
}
void insert(int x, int y, int v) {
  if (dep[x] < dep[y]) swap(x, y);
  int tmp = dep[x] - dep[y];
  for (int i = (int)(0); i <= (int)(16); i++)
    if (tmp & (1 << i)) Mnv[x][i] = min(Mnv[x][i], v), x = Fa[x][i];
  if (x == y) return;
  for (int i = (int)(16); i >= (int)(0); i--)
    if (Fa[x][i] != Fa[y][i]) {
      Mnv[x][i] = min(Mnv[x][i], v);
      Mnv[y][i] = min(Mnv[y][i], v);
      x = Fa[x][i];
      y = Fa[y][i];
    }
  Mnv[x][0] = min(Mnv[x][0], v);
  Mnv[y][0] = min(Mnv[y][0], v);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)(1); i <= (int)(m); i++) {
    scanf("%d%d%d", &E[i].x, &E[i].y, &E[i].v);
    E[i].id = i;
  }
  sort(E + 1, E + m + 1);
  for (int i = (int)(1); i <= (int)(n); i++) fa[i] = i;
  for (int i = (int)(1); i <= (int)(m); i++) {
    int x = get(E[i].x), y = get(E[i].y);
    if (x != y) {
      used[E[i].id] = 1;
      add(E[i].x, E[i].y, E[i].v, E[i].id);
      add(E[i].y, E[i].x, E[i].v, E[i].id);
      fa[x] = y;
    }
  }
  dfs(1);
  for (int i = (int)(1); i <= (int)(16); i++)
    for (int j = (int)(1); j <= (int)(n); j++) {
      Fa[j][i] = Fa[Fa[j][i - 1]][i - 1];
      Fav[j][i] = max(Fav[j][i - 1], Fav[Fa[j][i - 1]][i - 1]);
    }
  for (int i = (int)(0); i <= (int)(16); i++)
    for (int j = (int)(1); j <= (int)(n); j++) Mnv[i][j] = 1000000000;
  for (int i = (int)(1); i <= (int)(m); i++)
    if (!used[E[i].id]) {
      ans[E[i].id] = Query(E[i].x, E[i].y);
      insert(E[i].x, E[i].y, E[i].v);
    }
  for (int i = (int)(16); i >= (int)(1); i--)
    for (int j = (int)(1); j <= (int)(n); j++) {
      Mnv[j][i - 1] = min(Mnv[j][i - 1], Mnv[j][i]);
      Mnv[Fa[j][i - 1]][i - 1] = min(Mnv[Fa[j][i - 1]][i - 1], Mnv[j][i]);
    }
  for (int i = (int)(2); i <= (int)(n); i++) ans[Faid[i]] = Fa[i][0];
  for (int i = (int)(1); i <= (int)(m); i++)
    if (!used[i]) printf("%d\n", ans[i]);
}