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;
using ll = long long;
using pii = pair<int, int>;
using vb = vector<bool>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
vector<pair<pii, pii>> edgeList;
set<pii> queries;
vector<vector<pii>> mst;
int n, m, a, b, e;
vi par, level;
vvi lca, max_weight;
const int LOG_MAX = 20;
int find_parent(int a) {
  if (par[a] < 0) return a;
  return par[a] = find_parent(par[a]);
}
void join(int a, int b) {
  int par_a = find_parent(a);
  int par_b = find_parent(b);
  par[par_b] = par_a;
}
void buildMST() {
  int size = edgeList.size();
  for (int i = 0; i < size; i++) {
    auto edge = edgeList[i];
    pii p1, p2;
    tie(p1, p2) = edge;
    tie(a, b) = p2;
    e = p1.first;
    if (find_parent(a) != find_parent(b)) {
      join(a, b);
      mst[a].push_back({e, b});
      mst[b].push_back({e, a});
    } else {
      queries.insert({p1.second, i});
    }
  }
}
void dfs(int node, int lvl, int par = -1) {
  level[node] = lvl;
  lca[node][0] = par;
  for (pii p : mst[node]) {
    int to;
    tie(e, to) = p;
    if (to != par) {
      max_weight[to][0] = e;
      dfs(to, lvl + 1, node);
    }
  }
}
void init() {
  dfs(1, 0);
  for (int j = 1; j <= LOG_MAX - 1; j++) {
    for (int i = 1; i <= n; i++) {
      if (lca[i][j - 1] != -1) {
        lca[i][j] = lca[lca[i][j - 1]][j - 1];
        if (lca[i][j] != -1)
          max_weight[i][j] =
              max(max_weight[i][j - 1], max_weight[lca[i][j - 1]][j - 1]);
      }
    }
  }
}
int find_lca(int a, int b) {
  if (level[a] > level[b]) swap(a, b);
  for (int i = LOG_MAX - 1; i >= 0; i--)
    if (level[b] - level[a] >= (1 << i)) b = lca[b][i];
  if (a == b) return a;
  for (int i = LOG_MAX - 1; i >= 0; i--) {
    if (lca[a][i] != lca[b][i]) {
      a = lca[a][i], b = lca[b][i];
    }
  }
  if (a != b) a = lca[a][0];
  return a;
}
int calc(int a, int c) {
  int ret = 0;
  for (int i = LOG_MAX - 1; i >= 0; i--) {
    if (level[a] - level[c] >= (1 << i)) {
      ret = max(ret, max_weight[a][i]);
      a = lca[a][i];
    }
  }
  return ret;
}
int getAns(int a, int b) {
  int c = find_lca(a, b);
  return max(calc(a, c), calc(b, c));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  par.assign(n + 1, -1), level.assign(n + 1, -1), mst.resize(n + 1);
  lca.assign(n + 1, vi(LOG_MAX, -1)), max_weight.assign(n + 1, vi(LOG_MAX, -1));
  for (int i = 0; i < (int)m; i++) {
    cin >> a >> b >> e;
    edgeList.push_back({{e, i}, {a, b}});
  }
  sort(edgeList.begin(), edgeList.end(),
       [&](pair<pii, pii> p1, pair<pii, pii> p2) {
         return p1.first.first < p2.first.first;
       });
  buildMST();
  if (queries.empty()) return 0;
  init();
  for (auto p : queries) {
    int i = p.second;
    auto edge = edgeList[i];
    pii p1, p2;
    tie(p1, p2) = edge;
    tie(a, b) = p2;
    e = p1.first;
    cout << getAns(a, b) << '\n';
  }
  return 0;
}