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;
struct Dsu {
  struct node_struct {
    int par, size;
    node_struct(int p, int s) : par(p), size(s) {}
    void merge(node_struct &b) {
      b.par = par;
      size += b.size;
    }
  };
  vector<node_struct> nodes;
  Dsu(int n) {
    nodes.reserve(n);
    for (int i = 0; i < n; ++i) nodes.emplace_back(i, 1);
  }
  int anc(int x) {
    while (x != nodes[x].par) x = nodes[x].par;
    return x;
  }
  bool unite(int x, int y) {
    int a = anc(x);
    int b = anc(y);
    if (a == b) return false;
    if (nodes[a].size < nodes[b].size) swap(a, b);
    nodes[a].merge(nodes[b]);
    return true;
  }
};
int ans[1 << 20];
bool query[1 << 20] = {0};
int tin[1 << 17], tout[1 << 17], pa[17][1 << 17], ma[17][1 << 17];
int anc(int v, int p) { return tin[p] <= tin[v] and tout[v] <= tout[p]; }
int path(int u, int v) {
  int ans = -1, lca;
  if (not anc(u, v)) {
    for (int i = 16; i >= 0; --i) {
      if (not anc(u, pa[i][v])) {
        ans = max(ans, ma[i][v]);
        v = pa[i][v];
      }
    }
    ans = max(ans, ma[0][v]);
    lca = v = pa[0][v];
  } else
    lca = v;
  if (u != lca) {
    for (int i = 16; i >= 0; --i) {
      if (not anc(lca, pa[i][u])) {
        ans = max(ans, ma[i][u]);
        u = pa[i][u];
      }
    }
    ans = max(ans, ma[0][u]);
    u = pa[0][u];
  }
  assert(u == v);
  return ans;
}
vector<pair<int, int>> g[1 << 17];
void dfs(int u, int p, int w) {
  pa[0][u] = p, ma[0][u] = w;
  for (int i = 1; i < 17; ++i) {
    pa[i][u] = pa[i - 1][pa[i - 1][u]];
    ma[i][u] = max(ma[i - 1][u], ma[i - 1][pa[i - 1][u]]);
  }
  static int cur = 0;
  tin[u] = cur++;
  for (auto [v, w] : g[u])
    if (v != p) dfs(v, u, w);
  tout[u] = cur;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  Dsu djs(n);
  vector<tuple<int, int, int, int>> Es;
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    --u, --v;
    Es.emplace_back(c, u, v, i);
  }
  sort(Es.begin(), Es.end());
  for (auto [c, u, v, i] : Es) {
    if (djs.unite(u, v)) {
      g[u].emplace_back(v, c);
      g[v].emplace_back(u, c);
    } else
      query[i] = true;
  }
  dfs(0, 0, -1);
  for (auto [c, u, v, i] : Es) {
    if (query[i]) {
      ans[i] = path(u, v);
    }
  }
  for (int i = 0; i < m; ++i)
    if (query[i]) cout << ans[i] << '\n';
}