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 {
  vector<int> par, sz;

 public:
  UnionFind() {}
  UnionFind(int n) {
    par = sz = vector<int>(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      sz[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sz[x] > sz[y]) {
      par[y] = x;
      sz[x] += sz[y];
    } else {
      par[x] = y;
      sz[y] += sz[x];
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sz[find(x)]; }
};
int n, m;
struct st {
  int a, b, c, id;
};
vector<st> es;
vector<pair<int, int> > query[200000];
int ok[2000000], ng[2000000];
int a[2000000], b[2000000], c[2000000];
int ans[2000000];
int main() {
  cin >> n >> m;
  for (int i = 0; i < (m); i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    a[i]--;
    b[i]--;
    es.push_back({a[i], b[i], c[i], i});
  }
  sort(es.begin(), es.end(), [](st a, st b) { return a.c < b.c; });
  UnionFind uf(n);
  vector<st> vs;
  vector<st> us;
  for (auto s : es) {
    if (uf.same(s.a, s.b)) {
      vs.push_back(s);
    } else {
      uf.unite(s.a, s.b);
      us.push_back(s);
    }
  }
  for (auto s : vs) {
    ok[s.id] = 0;
    ng[s.id] = us.size() + 1;
  }
  for (int loop = 0; loop < (35); loop++) {
    for (int i = 0; i < (us.size() + 1); i++) {
      query[i].clear();
    }
    for (auto s : vs) {
      int t = (ok[s.id] + ng[s.id]) / 2;
      query[t].push_back(pair<int, int>(t, s.id));
    }
    UnionFind uf(n);
    for (int i = 0; i < (us.size() + 1); i++) {
      for (auto p : query[i]) {
        if (uf.same(a[p.second], b[p.second]))
          ng[p.second] = i;
        else
          ok[p.second] = i;
      }
      if (i < us.size()) {
        uf.unite(us[i].a, us[i].b);
      }
    }
  }
  memset(ans, -1, sizeof(ans));
  for (auto s : vs) {
    ans[s.id] = (ok[s.id] == us.size() ? 1e9 : us[ok[s.id]].c);
  }
  for (int i = 0; i < (m); i++) {
    if (ans[i] != -1) {
      printf("%d\n", ans[i]);
    }
  }
}