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 = 1e6 + 5;
int n, m;
int ans[N];
int fa[N];
int GETFA(int u) {
  if (fa[u] == u)
    return u;
  else
    return fa[u] = GETFA(fa[u]);
}
struct NODE {
  int u, v, w, id;
};
bool cmp(NODE& p, NODE& q) { return p.w < q.w; }
vector<NODE> E, G[N];
void KRUS() {
  for (int i = 1; i <= n; i++) fa[i] = i, G[i].clear();
  sort(E.begin(), E.end(), cmp);
  int c = 0;
  for (int i = 0; i <= m - 1; i++) {
    NODE e = E[i];
    int fu = GETFA(e.u);
    int fv = GETFA(e.v);
    if (fu == fv) continue;
    fa[fu] = fv;
    c++;
    ans[e.id] = -1;
    G[e.u].push_back({e.u, e.v, e.w, e.id});
    G[e.v].push_back({e.v, e.u, e.w, e.id});
    if (c == n - 1) break;
  }
}
int d[N], pa[N][20], mx[N][20];
void BZ(int u, int f) {
  d[u] = d[f] + 1;
  for (int i = 1; i <= 17; i++) {
    pa[u][i] = pa[pa[u][i - 1]][i - 1];
    mx[u][i] = max(mx[u][i - 1], mx[pa[u][i - 1]][i - 1]);
  }
  int len = G[u].size();
  for (int i = 0; i <= len - 1; i++) {
    NODE e = G[u][i];
    if (e.v == f) continue;
    pa[e.v][0] = e.u;
    mx[e.v][0] = e.w;
    BZ(e.v, e.u);
  }
}
int LCA(int u, int v) {
  int res = 0;
  if (d[u] < d[v]) swap(u, v);
  for (int i = 17; i >= 0; i--)
    if (d[u] - (1 << i) >= d[v]) {
      res = max(res, mx[u][i]);
      u = pa[u][i];
    }
  if (u == v) return res;
  for (int i = 17; i >= 0; i--)
    if (pa[u][i] != pa[v][i]) {
      res = max(res, max(mx[u][i], mx[v][i]));
      u = pa[u][i], v = pa[v][i];
    }
  return max(res, max(mx[u][0], mx[v][0]));
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    E.clear();
    for (int i = 1; i <= m; i++) {
      int u, v, w;
      scanf("%d%d%d", &u, &v, &w);
      E.push_back({u, v, w, i});
      ans[i] = 0;
    }
    KRUS();
    d[0] = 0;
    BZ(1, 0);
    for (int i = 0; i <= m - 1; i++) {
      int ind = E[i].id;
      if (ans[ind])
        ans[ind] = 0;
      else
        ans[ind] = LCA(E[i].u, E[i].v);
    }
    for (int i = 1; i <= m; i++)
      if (ans[i]) printf("%d\n", ans[i]);
  }
  return 0;
}