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 Edge {
  int u;
  int v;
  int c;
  int i;
  bool operator<(const Edge &a) const { return c < a.c; }
  bool operator==(const Edge &a) const {
    return u == a.u && v == a.v && c == a.c;
  }
};
struct Dsu {
  Dsu(const int N) : N(N), p(N) { Reset(); }
  void Reset() {
    for (int i = 0; i < N; ++i) {
      p[i] = i;
    }
  }
  void Join(const int u, const int v) {
    const int pu = FindParent(u);
    const int pv = FindParent(v);
    if (pu != pv) {
      if (rand() & 1) {
        p[pu] = pv;
      } else {
        p[pv] = pu;
      }
    }
  }
  int FindParent(const int u) {
    if (p[u] == u) {
      return u;
    }
    return p[u] = FindParent(p[u]);
  }
  const int N;
  vector<int> p;
};
struct Query {
  int l;
  int r;
  int i;
  int next;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<Edge> edges(m);
  for (int i = 0; i < m; ++i) {
    cin >> edges[i].u >> edges[i].v >> edges[i].c;
    --edges[i].u;
    --edges[i].v;
    edges[i].i = i;
  }
  sort(edges.begin(), edges.end());
  vector<int> answer(m, -1);
  Dsu dsu(n);
  for (int i = 0; i < m; ++i) {
    const auto e = edges[i];
    if (dsu.FindParent(e.u) == dsu.FindParent(e.v)) {
      answer[e.i] = 1000000000;
      continue;
    }
    dsu.Join(e.u, e.v);
  }
  vector<int> head(m, -1);
  int lastQuery = -1;
  vector<Query> queries(m + 1);
  for (int i = 0; i < m; ++i) {
    const auto e = edges[i];
    if (answer[e.i] == -1) {
      continue;
    }
    Query q;
    q.l = 0;
    q.r = m;
    q.i = i;
    q.next = lastQuery;
    lastQuery = queries.size();
    head[m / 2] = lastQuery;
    queries.push_back(q);
  }
  while (true) {
    bool foundSomething = false;
    dsu.Reset();
    vector<int> rq;
    for (int i = 0; i < m; ++i) {
      const auto e = edges[i];
      if (dsu.FindParent(e.u) != dsu.FindParent(e.v)) {
        dsu.Join(e.u, e.v);
      }
      rq.clear();
      for (int j = head[i]; j != -1; j = queries[j].next) {
        rq.push_back(j);
      }
      head[i] = -1;
      for (size_t j = 0; j < rq.size(); ++j) {
        const int mid = i;
        int lo = queries[rq[j]].l;
        int hi = queries[rq[j]].r;
        const int id = queries[rq[j]].i;
        if (dsu.FindParent(edges[id].u) == dsu.FindParent(edges[id].v)) {
          hi = mid;
        } else {
          lo = mid + 1;
        }
        if (lo == hi) {
          if (lo < m) {
            answer[edges[id].i] = edges[lo].c;
          }
          continue;
        }
        queries[rq[j]].l = lo;
        queries[rq[j]].r = hi;
        queries[rq[j]].next = head[(lo + hi) / 2];
        head[(lo + hi) / 2] = rq[j];
        foundSomething = true;
      }
    }
    if (!foundSomething) {
      break;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (answer[i] != -1) {
      cout << answer[i] << " ";
    }
  }
  return 0;
}