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>
const long long INF = 2000000007;
const long long BIG_INF = 2000000000000000005;
const long long mod = 1000000007;
const long long P = 31;
const long double PI = 3.141592653589793238462643;
using namespace std;
vector<pair<long long, long long> > dir = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
bool valid(long long x, long long y, long long n, long long m) {
  return x >= 0 && y >= 0 && x < n && y < m;
}
mt19937 rng(1999999973);
const int N = 100000 + 5, M = 1000000 + 5, Lg = 17;
int n, m, h[N], dp[N][Lg], mx[N][Lg], p[N], order[M], U[M], V[M], W[M];
vector<pair<long long, long long> > g[N];
bool good[M];
int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  for (int j = Lg - 1; j >= 0; j--) {
    if (h[dp[u][j]] >= h[v]) u = dp[u][j];
  }
  if (u == v) return u;
  for (int j = Lg - 1; j >= 0; j--) {
    if (dp[u][j] != dp[v][j]) u = dp[u][j], v = dp[v][j];
  }
  return dp[u][0];
}
int find_set(int v) {
  if (p[v] == v) return v;
  p[v] = find_set(p[v]);
  return p[v];
}
bool comp(int x, int y) { return W[x] < W[y]; }
void dfs(int v, int pr, int ds, int w) {
  dp[v][0] = pr;
  mx[v][0] = w;
  h[v] = ds;
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i].first != pr) dfs(g[v][i].first, v, ds + 1, g[v][i].second);
  }
}
void precalc() {
  for (int j = 1; j < Lg; j++) {
    for (int i = 0; i < n; i++) {
      dp[i][j] = dp[dp[i][j - 1]][j - 1];
      mx[i][j] = max(mx[i][j - 1], mx[dp[i][j - 1]][j - 1]);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    order[i] = i;
    cin >> U[i] >> V[i] >> W[i];
    U[i]--, V[i]--;
  }
  for (int i = 0; i < n; i++) p[i] = i;
  sort(order, order + m, comp);
  for (int i = 0; i < m; i++) {
    int cur = order[i];
    if (find_set(U[cur]) != find_set(V[cur])) {
      g[U[cur]].push_back(make_pair(V[cur], W[cur]));
      g[V[cur]].push_back(make_pair(U[cur], W[cur]));
      p[find_set(U[cur])] = find_set(V[cur]);
      good[cur] = true;
    }
  }
  dfs(0, 0, 0, -INF);
  precalc();
  for (int i = 0; i < m; i++) {
    if (good[i]) continue;
    int lc = lca(U[i], V[i]);
    int ans = -INF;
    int cur = h[U[i]] - h[lc], u = U[i], v = V[i];
    while (cur > 0) {
      ans = max(ans, mx[u][__builtin_ctz(cur)]);
      u = dp[u][__builtin_ctz(cur)];
      cur &= (cur - 1);
    }
    u = v;
    cur = h[v] - h[lc];
    while (cur > 0) {
      ans = max(ans, mx[u][__builtin_ctz(cur)]);
      u = dp[u][__builtin_ctz(cur)];
      cur &= (cur - 1);
    }
    cout << ans << '\n';
  }
  return 0;
}