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>
const int N = 1e5 + 10;
const int M = 1e6 + 10;
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = getchar();
  }
  x *= p;
}
int n, m, posx, posy;
int L[N * 30], R[N * 30], fa[N * 30], dep[N * 30];
int root[M];
bool ok[M];
struct node {
  int u, v, w, id;
} e[M];
bool operator<(node a, node b) { return a.w < b.w; }
namespace Persistant_Union_Set {
int cnt;
void build(int &rt, int l, int r) {
  rt = ++cnt;
  if (l == r) {
    fa[rt] = l;
    return;
  }
  build(L[rt], l, ((l + r) >> 1));
  build(R[rt], ((l + r) >> 1) + 1, r);
}
void merge(int last, int &rt, int l, int r, int pos, int Fa) {
  rt = ++cnt;
  L[rt] = L[last], R[rt] = R[last];
  if (l == r) {
    fa[rt] = Fa;
    dep[rt] = dep[last];
    return;
  }
  if (pos <= ((l + r) >> 1))
    merge(L[last], L[rt], l, ((l + r) >> 1), pos, Fa);
  else
    merge(R[last], R[rt], ((l + r) >> 1) + 1, r, pos, Fa);
}
void update(int rt, int l, int r, int pos) {
  if (l == r) {
    dep[rt]++;
    return;
  }
  if (pos <= ((l + r) >> 1))
    update(L[rt], l, ((l + r) >> 1), pos);
  else
    update(R[rt], ((l + r) >> 1) + 1, r, pos);
}
int query(int rt, int l, int r, int pos) {
  if (l == r) return rt;
  if (pos <= ((l + r) >> 1))
    return query(L[rt], l, ((l + r) >> 1), pos);
  else
    return query(R[rt], ((l + r) >> 1) + 1, r, pos);
}
int find(int rt, int pos) {
  int now = query(rt, 1, n, pos);
  if (fa[now] == pos) return now;
  return find(rt, fa[now]);
}
}  // namespace Persistant_Union_Set
using namespace Persistant_Union_Set;
int x, y, l, r, ans[M];
bool in(int mid, int x, int y) {
  posx = find(root[mid], x);
  posy = find(root[mid], y);
  return fa[posx] == fa[posy];
}
int main() {
  read(n);
  read(m);
  memset(ans, -1, sizeof ans);
  build(root[0], 1, n);
  for (int i = 1; i <= m; ++i)
    read(e[i].u), read(e[i].v), read(e[i].w), e[i].id = i;
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= m; i++) {
    x = e[i].u;
    y = e[i].v;
    root[i] = root[i - 1];
    posx = find(root[i], x);
    posy = find(root[i], y);
    if (fa[posx] != fa[posy]) {
      if (dep[posx] > dep[posy]) swap(posx, posy);
      merge(root[i - 1], root[i], 1, n, fa[posx], fa[posy]);
      if (dep[posx] == dep[posy]) update(root[i], 1, n, fa[posy]);
      ok[i] = 1;
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (ok[i]) continue;
    l = 0;
    r = i;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (in(mid, e[i].u, e[i].v))
        r = mid - 1;
      else
        l = mid + 1;
    }
    ans[e[i].id] = e[l].w;
  }
  for (int i = 1; i <= m; ++i) {
    if (~ans[i]) printf("%d\n", ans[i]);
  }
  return 0;
}