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;
long long n, m, nn = 0, dsu[100069], pr[100069][17], dp[100069][17], bl[100069],
                dh[100069], cdh = 0;
pair<pair<long long, long long>, pair<long long, long long>> a[1000069];
pair<long long, pair<long long, long long>> ed[1000069];
vector<pair<long long, long long>> al[100069];
bitset<100069> vtd;
long long fd(long long x) {
  if (dsu[x] != x) {
    dsu[x] = fd(dsu[x]);
  }
  return dsu[x];
}
void dfs(long long x) {
  long long i, j, sz = al[x].size(), l, w;
  vtd[x] = 1;
  dh[x] = cdh;
  cdh++;
  for (i = 0; i < sz; i++) {
    l = al[x][i].first;
    w = al[x][i].second;
    if (!vtd[l]) {
      pr[l][0] = x;
      dp[l][0] = w;
      for (j = 1; j - 1 < bl[pr[l][j - 1]]; j++) {
        pr[l][j] = pr[pr[l][j - 1]][j - 1];
        dp[l][j] = max(dp[l][j - 1], dp[pr[l][j - 1]][j - 1]);
      }
      bl[l] = j;
      dfs(l);
    }
  }
  cdh--;
}
int main() {
  long long i, j, ii, k, l, w, pz, z, p[2];
  scanf("%lld%lld", &n, &m);
  for (i = 1; i <= n; i++) {
    dsu[i] = i;
  }
  for (i = 1; i <= m; i++) {
    scanf("%lld%lld%lld", &k, &l, &w);
    a[i] = {{w, i}, {k, l}};
  }
  sort(a + 1, a + m + 1);
  for (i = 1; i <= m; i++) {
    k = a[i].second.first;
    l = a[i].second.second;
    w = a[i].first.first;
    pz = a[i].first.second;
    if (fd(k) != fd(l)) {
      dsu[fd(l)] = fd(k);
      al[k].push_back({l, w});
      al[l].push_back({k, w});
    } else {
      nn++;
      ed[nn] = {pz, {k, l}};
    }
  }
  dfs(1);
  sort(ed + 1, ed + nn + 1);
  for (i = 1; i <= nn; i++) {
    p[0] = ed[i].second.first;
    p[1] = ed[i].second.second;
    z = -1e18;
    for (ii = 0; ii < 2; ii++) {
      for (j = 16; j >= 0; j--) {
        if (j < bl[p[ii]] && dh[pr[p[ii]][j]] >= dh[p[!ii]]) {
          z = max(z, dp[p[ii]][j]);
          p[ii] = pr[p[ii]][j];
        }
      }
    }
    for (j = 16; j >= 0; j--) {
      if (j < bl[p[0]] && pr[p[0]][j] != pr[p[1]][j]) {
        for (ii = 0; ii < 2; ii++) {
          z = max(z, dp[p[ii]][j]);
          p[ii] = pr[p[ii]][j];
        }
      }
    }
    if (p[0] != p[1]) {
      z = max(z, max(dp[p[0]][0], dp[p[1]][0]));
    }
    printf("%lld\n", z);
  }
}