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 GCC optimize("O3")
#pragma GCC target("tune=native")
#pragma GCC optimize("fast-math")
using namespace std;
const int DEBUG = 0;
mt19937 gen(
    (unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
#pragma comment(linker, "/STACK:16777216")
struct dsu {
  vector<int> p, sz;
  dsu() {}
  dsu(int size) {
    p = vector<int>(size);
    sz = vector<int>(size);
    for (int i = 0; i < size; i++) {
      p[i] = i;
      sz[i] = 1;
    }
  }
  int find_set(int v) {
    if (p[v] == v) return v;
    return p[v] = find_set(p[v]);
  }
  int merge(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a == b) return 0;
    if (sz[a] < sz[b]) swap(a, b);
    sz[a] += sz[b];
    p[b] = a;
    return 1;
  }
};
const int N = (int)1e5 + 100;
const int LOG = 20;
const int E = (int)1e6 + 100;
struct edge {
  int s, e, c, id;
};
bool operator<(const edge& a, const edge& b) { return a.c < b.c; }
vector<edge> edges;
int nv, ne;
vector<edge> g[N];
int tin[N], tout[N];
int timer;
int up[N][LOG];
int maxCost[N][LOG];
int h[N];
void dfs(int v, int p = 0, int pCost = 0) {
  tin[v] = timer++;
  up[v][0] = p;
  maxCost[v][0] = pCost;
  for (int i = 1; i < LOG; i++) {
    up[v][i] = up[up[v][i - 1]][i - 1];
    maxCost[v][i] = max(maxCost[v][i - 1], maxCost[up[v][i - 1]][i - 1]);
  }
  for (edge e : g[v]) {
    if (e.e == p) continue;
    h[e.e] = h[v] + 1;
    dfs(e.e, v, e.c);
  }
  tout[v] = timer++;
}
char inMst[E];
void build_mst() {
  dsu tree(nv);
  sort(edges.begin(), edges.end());
  for (int i = 0; i < ne; i++) {
    if (tree.merge(edges[i].s, edges[i].e)) {
      inMst[edges[i].id] = 1;
      int s = edges[i].s;
      int e = edges[i].e;
      int c = edges[i].c;
      g[s].push_back({s, e, c, -1});
      g[e].push_back({e, s, c, -1});
    }
  }
}
int upper(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }
int lca(int a, int b) {
  if (h[a] < h[b]) swap(a, b);
  if (upper(b, a)) return b;
  for (int i = LOG - 1; i >= 0; i--) {
    if (!upper(up[a][i], b)) a = up[a][i];
  }
  return up[a][0];
}
int get_max_cost_up(int a, int b) {
  int dist = h[b] - h[a];
  int res = 0;
  for (int i = 0; i < LOG; i++) {
    if (dist & (1 << i)) {
      res = max(res, maxCost[b][i]);
      b = up[b][i];
    }
  }
  return res;
}
int get_max_cost(int a, int b) {
  int v = lca(a, b);
  return max(get_max_cost_up(v, a), get_max_cost_up(v, b));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(cout.fixed);
  cout.precision(12);
  auto START_TIME = chrono::high_resolution_clock::now();
  cin >> nv >> ne;
  edges = vector<edge>(ne);
  for (int i = 0; i < ne; i++) {
    cin >> edges[i].s >> edges[i].e >> edges[i].c;
    edges[i].id = i;
    --edges[i].s;
    --edges[i].e;
  }
  build_mst();
  dfs(0);
  sort(edges.begin(), edges.end(),
       [](const edge& a, const edge& b) { return a.id < b.id; });
  for (int i = 0; i < ne; i++) {
    if (inMst[i]) continue;
    cout << get_max_cost(edges[i].s, edges[i].e) << "\n";
  }
  return 0;
}