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;
class UnionFind {
 public:
  explicit UnionFind(int size) : m_size(size, 1), m_subgroups(size) {
    m_parent.reserve(size);
    for (int i = 0; i < size; ++i) m_parent.push_back(i);
  }
  int subgroups() const { return m_subgroups; }
  int groupSize(int i) { return m_size[root(i)]; }
  int root(int i) {
    return (m_parent[i] == i) ? i : (m_parent[i] = root(m_parent[i]));
  }
  bool connected(int i, int j) { return root(i) == root(j); }
  void connect(int i, int j) {
    int root1 = root(i);
    int root2 = root(j);
    if (root1 != root2) {
      if (m_size[root1] < m_size[root2]) {
        m_parent[root1] = root2;
        m_size[root2] += m_size[root1];
      } else {
        m_parent[root2] = root1;
        m_size[root1] += m_size[root2];
      }
      --m_subgroups;
    }
  }

 private:
  vector<int> m_parent, m_size;
  int m_subgroups;
};
struct Edge {
  int u, v, e, id;
  bool operator<(const Edge& o) const { return e < o.e; }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  cin.ignore();
  vector<Edge> edges(m);
  map<pair<int, int>, list<int>> ccEdges;
  for (int i = 0; i < m; ++i) {
    Edge& edge = edges[i];
    cin >> edge.u >> edge.v >> edge.e;
    cin.ignore();
    --edge.u;
    --edge.v;
    edge.id = i;
    ccEdges.emplace(make_pair(edge.u, edge.v), list<int>{i});
    ccEdges.emplace(make_pair(edge.v, edge.u), list<int>{i});
  }
  sort(edges.begin(), edges.end());
  UnionFind uf(n);
  vector<int> ans(m, -1);
  for (Edge& edge : edges) {
    int ru = uf.root(edge.u), rv = uf.root(edge.v);
    if (!uf.connected(ru, rv)) {
      auto itUv = ccEdges.find(make_pair(ru, rv));
      if (itUv != ccEdges.end()) {
        for (auto id : itUv->second) {
          if (id != edge.id) ans[id] = edge.e;
        }
        ccEdges.erase(itUv);
        ccEdges.erase(make_pair(rv, ru));
      }
      uf.connect(edge.u, edge.v);
      int r2 = uf.root(ru);
      for (int r1 : {ru, rv}) {
        if (r1 != r2) {
          auto lower = ccEdges.lower_bound(make_pair(r1, 0));
          auto it = lower;
          while (it != ccEdges.end() && it->first.first == r1) {
            auto& list = ccEdges[make_pair(r2, it->first.second)];
            list.splice(list.end(), it->second);
            auto itMirror = ccEdges.find(make_pair(it->first.second, r1));
            if (itMirror == ccEdges.end()) exit(1);
            auto& listMirror = ccEdges[make_pair(it->first.second, r2)];
            listMirror.splice(listMirror.end(), itMirror->second);
            ccEdges.erase(itMirror);
            ++it;
          }
          ccEdges.erase(lower, it);
        }
      }
    }
  }
  for (int a : ans) {
    if (a != -1) cout << a << '\n';
  }
  cout.flush();
  return 0;
}