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;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 1e9 + 10;
struct dsu0 {
  vector<int> par, siz;
  int n;
  int cc;
  int largest;
  void init(int n) {
    assert(n > 0);
    this->n = n;
    cc = n;
    par.resize(n + 10);
    siz.resize(n + 10);
    for (int i = 0; i < n; i++) par[i] = i, siz[i] = 1;
    largest = 1;
  }
  int parent(int x) {
    assert(x >= 0 && x < n);
    return par[x] == x ? x : par[x] = parent(par[x]);
  }
  void join(int x, int y) {
    x = parent(x);
    y = parent(y);
    if (x == y) return;
    cc--;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    largest = max(largest, siz[x]);
  }
};
int n, m;
bool mst[maxn];
int ans[maxn];
int w[maxn], u[maxn], v[maxn];
int p[maxn];
const int LOG = 17;
vector<pair<int, int>> g[maxn];
int par[LOG + 1][maxn];
int dep[maxn];
int upEd[LOG + 1][maxn];
void dfs(int at, int p = -1) {
  if (p != -1) {
    par[0][at] = p;
    for (int j = 1; j < LOG; j++) {
      par[j][at] = par[j - 1][par[j - 1][at]];
    }
    for (int j = 1; j < LOG; j++) {
      upEd[j][at] = max(upEd[j - 1][at], upEd[j - 1][par[j - 1][at]]);
    }
  }
  for (auto ed : g[at]) {
    int to = ed.second;
    if (to != p) {
      int wei = ed.first;
      upEd[0][to] = wei;
      dep[to] = 1 + dep[at];
      dfs(to, at);
    }
  }
}
int lca(int u, int v) {
  if (u == v) return v;
  if (dep[u] < dep[v]) swap(u, v);
  int dx = dep[u] - dep[v];
  for (int j = LOG - 1; j >= 0; j--) {
    if (dx >> j & 1) {
      u = par[j][u];
    }
  }
  assert(dep[u] == dep[v]);
  if (u == v) return v;
  for (int j = LOG - 1; j >= 0; j--) {
    if (par[j][u] != par[j][v]) {
      u = par[j][u];
      v = par[j][v];
    }
  }
  return par[0][u];
}
int walk(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int res = 0;
  for (int j = LOG - 1; j >= 0; j--) {
    int to = par[j][u];
    if (dep[to] > dep[v]) {
      res = max(res, upEd[j][u]);
      u = to;
    }
  }
  res = max(res, upEd[0][u]);
  return res;
}
int get(int u, int v) {
  assert(u != v);
  int mid = lca(u, v);
  int res = 0;
  if (mid != u) res = max(res, walk(u, mid));
  if (mid != v) res = max(res, walk(v, mid));
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(ans, -1, sizeof(ans));
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i] >> w[i];
    --u[i];
    --v[i];
  }
  iota(p, p + m, 0);
  sort(p, p + m, [&](int i, int j) { return w[i] < w[j]; });
  dsu0 dsu;
  dsu.init(n);
  for (int i = 0; i < m; i++) {
    int a = u[p[i]];
    int b = v[p[i]];
    int wei = w[p[i]];
    if (dsu.parent(a) != dsu.parent(b)) {
      mst[p[i]] = true;
      dsu.join(a, b);
      g[a].push_back({wei, b});
      g[b].push_back({wei, a});
    }
  }
  dfs(0);
  for (int i = 0; i < m; i++) {
    if (mst[p[i]]) continue;
    ans[p[i]] = get(u[p[i]], v[p[i]]);
  }
  for (int i = 0; i < m; i++) {
    if (~ans[i]) {
      cout << ans[i] << "\n";
    }
  }
  return 0;
}