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;
const int N = 1e5 + 1;
struct kek {
  int x, y, len, ind;
};
vector<kek> r;
vector<pair<int, int>> g[N];
bool cmp(const kek &a, const kek &b) { return a.len < b.len; }
bool cmp1(const kek &a, const kek &b) { return a.ind < b.ind; }
int p[N];
int root(int x) {
  if (p[x] == x) return x;
  return p[x] = root(p[x]);
}
void uni(int x, int y) {
  x = root(x), y = root(y);
  p[x] = y;
}
int lev[N];
int min_val[N][30];
int pc[N];
bool us[N];
int sz = 0;
int centr = 0;
int gdeep = 0;
void dfs_sz(int x, int pr) {
  sz++;
  for (int i = 0; i < g[x].size(); i++) {
    int y = g[x][i].first;
    if (y != pr && !us[y]) {
      dfs_sz(y, x);
    }
  }
}
void dfs_mx(int x, int pr, int mx) {
  min_val[x][gdeep] = mx;
  for (int i = 0; i < g[x].size(); i++) {
    int y = g[x][i].first;
    if (y != pr && !us[y]) {
      dfs_mx(y, x, max(mx, g[x][i].second));
    }
  }
}
int dfs(int x, int pr) {
  int dp = 1;
  int mx = 0;
  for (int i = 0; i < g[x].size(); i++) {
    int y = g[x][i].first;
    if (y != pr && !us[y]) {
      int dp1 = dfs(y, x);
      mx = max(mx, dp1);
      dp += dp1;
    }
  }
  if (mx * 2 <= sz && 2 * (sz - dp) <= sz) {
    centr = x;
  }
  return dp;
}
int n;
void bu(int x, int prec, int deep) {
  gdeep = deep;
  sz = 0;
  dfs_sz(x, -1);
  centr = 0;
  dfs(x, -1);
  x = centr;
  lev[x] = deep;
  us[x] = 1;
  pc[x] = prec;
  dfs_mx(x, -1, -1);
  for (int i = 0; i < g[x].size(); i++) {
    int y = g[x][i].first;
    if (!us[y]) {
      bu(y, x, deep + 1);
    }
  }
}
int getCenter(int a, int b) {
  while (lev[a] > lev[b]) a = pc[a];
  while (lev[a] < lev[b]) b = pc[b];
  while (a != b) a = pc[a], b = pc[b];
  return a;
}
int ans;
void dfs1(int x, int y, int pr, int t) {
  if (x == y) ans = max(ans, t);
  for (int i = 0; i < g[x].size(); i++) {
    int xx = g[x][i].first, len = g[x][i].second;
    if (xx != pr) {
      dfs1(xx, y, x, max(t, len));
    }
  }
}
int main() {
  int m;
  scanf("%d %d", &n, &m);
  for (int x = 1; x <= n; x++) {
    for (int i = 0; i < 30; i++) {
      min_val[x][i] = 1e9;
    }
  }
  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    r.push_back({x, y, z, i});
  }
  sort(r.begin(), r.end(), cmp);
  vector<int> indx;
  for (int x = 1; x <= n; x++) {
    p[x] = x;
  }
  for (int i = 0; i < r.size(); i++) {
    int x = r[i].x, y = r[i].y, len = r[i].len;
    if (root(x) != root(y)) {
      uni(x, y);
      g[x].push_back({y, len});
      g[y].push_back({x, len});
    } else {
      indx.push_back(r[i].ind);
    }
  }
  sort(indx.begin(), indx.end());
  bu(1, -1, 0);
  sort(r.begin(), r.end(), cmp1);
  for (int ind : indx) {
    int x = r[ind].x, y = r[ind].y;
    int c = getCenter(x, y);
    cout << max(min_val[x][lev[c]], min_val[y][lev[c]]) << endl;
  }
  return 0;
}