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>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 1e18;
template <typename T>
void read(T &x) {
  x = 0;
  int s = 1, c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') s = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  x *= s;
}
template <typename T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
const int maxn = 1e5 + 5, maxm = 1e6 + 5;
struct Edge {
  int u, v, c, id;
  bool operator<(const Edge &rhs) const { return c < rhs.c; }
} e[maxm];
int n, m;
int fa[maxn];
vector<pair<int, int> > adj[maxn];
int f[maxn][20], dis[maxn][20], d[maxn];
vector<Edge> v;
int find(int v) { return v == fa[v] ? v : fa[v] = find(fa[v]); }
void dfs(int u, int fa) {
  d[u] = d[fa] + 1;
  for (pair<int, int> x : adj[u])
    if (x.first ^ fa) {
      int v = x.first, c = x.second;
      f[v][0] = u;
      dis[v][0] = c;
      dfs(v, u);
    }
}
int LCA(int x, int y, int op) {
  int res = 0;
  if (d[x] > d[y]) swap(x, y);
  for (int t = 19; t >= 0; t--)
    if (d[x] <= d[f[y][t]]) {
      res = max(res, dis[y][t]);
      y = f[y][t];
    }
  if (x == y) return op ? res : x;
  for (int t = 19; t >= 0; t--)
    if (f[x][t] != f[y][t]) {
      res = max(res, max(dis[x][t], dis[y][t]));
      x = f[x][t], y = f[y][t];
    }
  res = max(res, max(dis[x][0], dis[y][0]));
  return op ? res : f[x][0];
}
int main() {
  read(n), read(m);
  for (int i = 1; i <= m; i++) {
    read(e[i].u), read(e[i].v), read(e[i].c);
    e[i].id = i;
  }
  sort(e + 1, e + 1 + m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int p = find(e[i].u), t = find(e[i].v);
    if (p != t) {
      adj[e[i].u].emplace_back(e[i].v, e[i].c);
      adj[e[i].v].emplace_back(e[i].u, e[i].c);
      fa[p] = t;
    } else
      v.emplace_back(e[i]);
  }
  dfs(1, 0);
  for (int j = 1; j <= 19; j++)
    for (int i = 1; i <= n; i++) {
      f[i][j] = f[f[i][j - 1]][j - 1];
      dis[i][j] = max(dis[i][j - 1], dis[f[i][j - 1]][j - 1]);
    }
  sort((v.begin()), (v.end()), [&](Edge x, Edge y) { return x.id < y.id; });
  for (auto i : v) {
    int lca = LCA(i.u, i.v, 0);
    printf("%d\n", max(LCA(i.u, lca, 1), LCA(i.v, lca, 1)));
  }
}