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;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
struct ppUF {
  vector<int> par, ti;
  vector<vector<pair<int, int>>> his;
  ppUF(int n) : ti(n, inf + 1), par(n, -1), his(n) {
    for (auto &vs : his) vs.emplace_back(-1, -1);
  }
  int find(int t, int x) {
    if (ti[x] > t) return x;
    return find(t, par[x]);
  }
  bool unite(int t, int x, int y) {
    x = find(t, x);
    y = find(t, y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    his[x].emplace_back(t, par[x]);
    par[y] = x;
    ti[y] = t;
    return true;
  }
  bool same(int t, int x, int y) { return find(t, x) == find(t, y); }
  int time(int x, int y) {
    if (!same(inf, x, y)) return -1;
    int ok = inf, ng = -1, mid = 0;
    while (ok - ng > 1) {
      mid = (ok + ng) / 2;
      if (same(mid, x, y))
        ok = mid;
      else
        ng = mid;
    }
    return ok;
  }
  int size(int t, int x) {
    x = find(t, x);
    return -prev(
                lower_bound(his[x].begin(), his[x].end(), pair<int, int>(t, 0)))
                ->second;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m), c(m);
  for (int i = (int)(0); i < (int)(m); ++i) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
  }
  vector<int> ord(m);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int s, int t) { return c[s] < c[t]; });
  ppUF uf(n + 1);
  vector<ll> ans(m, -1);
  for (auto i : ord) {
    if (!uf.same(inf, a[i], b[i]))
      uf.unite(c[i], a[i], b[i]);
    else {
      ans[i] = uf.time(a[i], b[i]);
    }
  }
  for (int i = (int)(0); i < (int)(m); ++i) {
    if (ans[i] == -1) continue;
    printf("%lld\n", ans[i]);
  }
  return 0;
}