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;
int n, m, f[100021][20], Max[100021][20], Min[100021][20];
int ff[100021], ans[1000021], h[100021], id[100021];
int find(int x) { return ff[x] == x ? x : ff[x] = find(ff[x]); }
struct edge {
  int a, b, c, id, fg;
  bool operator<(const edge& z) const { return c < z.c; }
} e[1000021];
vector<tuple<int, int, int>> g[100021];
void dfs1(int u, int fa) {
  h[u] = h[fa] + 1;
  f[u][0] = fa;
  Min[u][0] = 1e9;
  for (int i = 1; i < 20; i++) {
    f[u][i] = f[f[u][i - 1]][i - 1];
    Max[u][i] = max(Max[u][i], max(Max[u][i - 1], Max[f[u][i - 1]][i - 1]));
    Min[u][i] = 1e9;
  }
  for (auto v : g[u]) {
    if (get<0>(v) == fa) continue;
    Max[get<0>(v)][0] = get<1>(v);
    id[get<0>(v)] = get<2>(v);
    dfs1(get<0>(v), u);
  }
}
int query(int a, int b, int w) {
  if (h[a] > h[b]) swap(a, b);
  int ans = 0;
  for (int i = 19; i >= 0; i--) {
    if (h[f[b][i]] >= h[a]) {
      ans = max(ans, Max[b][i]);
      Min[b][i] = min(Min[b][i], w);
      b = f[b][i];
    }
  }
  if (a == b) return ans;
  for (int i = 19; i >= 0; i--) {
    if (f[a][i] == f[b][i]) continue;
    ans = max(ans, max(Max[a][i], Max[b][i]));
    Min[a][i] = min(Min[a][i], w);
    Min[b][i] = min(Min[b][i], w);
    a = f[a][i];
    b = f[b][i];
  }
  ans = max(ans, max(Max[a][0], Max[b][0]));
  Min[a][0] = min(Min[a][0], w);
  Min[b][0] = min(Min[b][0], w);
  return ans;
}
void dfs2(int u, int fa) {
  for (auto v : g[u]) {
    if (get<0>(v) == fa) continue;
    dfs2(get<0>(v), u);
  }
  for (int i = 19; i > 0; i--) {
    Min[u][i - 1] = min(Min[u][i - 1], Min[u][i]);
    Min[f[u][i - 1]][i - 1] = min(Min[f[u][i - 1]][i - 1], Min[u][i]);
  }
  ans[id[u]] = Min[u][0];
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> e[i].a >> e[i].b >> e[i].c;
    e[i].id = i;
  }
  sort(e + 1, e + 1 + m);
  for (int i = 1; i <= n; i++) ff[i] = i;
  for (int i = 1; i <= m; i++) {
    if (find(e[i].a) != find(e[i].b)) {
      e[i].fg = 1;
      ff[find(e[i].a)] = find(e[i].b);
      g[e[i].a].push_back(make_tuple(e[i].b, e[i].c, e[i].id));
      g[e[i].b].push_back(make_tuple(e[i].a, e[i].c, e[i].id));
    } else
      e[i].fg = 0;
  }
  dfs1(1, 0);
  memset(ans, -1, sizeof(ans));
  for (int i = 1; i <= m; i++) {
    if (e[i].fg) continue;
    ans[e[i].id] = query(e[i].a, e[i].b, e[i].c);
  }
  for (int i = 1; i <= m; i++)
    if (~ans[i]) cout << ans[i] << endl;
  return 0;
}