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;
int fa[100005];
const int maxn = 100005;
int n, m, tot;
int find(int x) {
  if (fa[x] != x) {
    fa[x] = find(fa[x]);
  }
  return fa[x];
}
struct edge {
  int u, v, w, id;
} E[1000005], E2[1000005];
bool operator<(const struct edge &a, const struct edge &b) { return a.w < b.w; }
vector<pair<int, int> > e[maxn];
void kruscal() {
  sort(E, E + m);
  int s = 0;
  for (int i = 0; i < m; i++) {
    int fx = find(E[i].u);
    int fy = find(E[i].v);
    if (fx != fy && s <= n - 1) {
      s++;
      fa[fx] = fy;
      e[E[i].u].push_back(make_pair(E[i].v, E[i].w));
      e[E[i].v].push_back(make_pair(E[i].u, E[i].w));
    } else {
      E2[tot++] = E[i];
    }
  }
}
int f[100005][20];
int mx[100005][20];
int dep[100005];
void dfs(int u, int fa) {
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i].first;
    if (v == fa) continue;
    f[v][0] = u;
    mx[v][0] = e[u][i].second;
    dep[v] = dep[u] + 1;
    dfs(v, u);
  }
}
void init() {
  for (int i = 1; i < 18; i++) {
    for (int u = 1; u <= n; u++) f[u][i] = f[f[u][i - 1]][i - 1];
  }
  for (int i = 1; i < 18; i++) {
    for (int u = 1; u <= n; u++)
      mx[u][i] = max(mx[u][i - 1], mx[f[u][i - 1]][i - 1]);
  }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) {
    swap(u, v);
  }
  int d = dep[u] - dep[v];
  int maxn = 0;
  for (int i = 0; i < 18; i++) {
    if (d & (1 << i)) {
      maxn = max(maxn, mx[u][i]);
      u = f[u][i];
      d ^= (1 << i);
    }
  }
  while (u != v) {
    for (int i = 17; i >= 0; i--) {
      if (f[u][i] != f[v][i] || i == 0)
        maxn = max(maxn, max(mx[u][i], mx[v][i])), u = f[u][i], v = f[v][i];
    }
  }
  return maxn;
}
int ans[1000005];
int main(int argc, char **argv) {
  scanf("%d%d", &n, &m);
  tot = 0;
  for (int i = 0; i <= 100000; i++) fa[i] = i;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &E[i].u, &E[i].v, &E[i].w);
    E[i].id = i;
  }
  kruscal();
  f[1][0] = 1;
  dfs(1, -1);
  init();
  for (int i = 0; i < tot; i++) {
    int u = E2[i].u;
    int v = E2[i].v;
    ans[E2[i].id] = lca(u, v);
  }
  for (int i = 0; i < m; i++) {
    if (ans[i]) printf("%d\n", ans[i]);
  }
  return 0;
}