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 root(vector<int>& r, int i) {
  while (r[i] != i) {
    r[i] = r[r[i]];
    i = r[i];
  }
  return i;
}
void wunion(vector<int>& r, vector<int>& size, int a, int b) {
  int root_a = root(r, a);
  int root_b = root(r, b);
  if (root_a != root_b) {
    if (size[root_a] < size[root_b]) {
      r[root_a] = r[root_b];
      size[root_b] += size[root_a];
    } else {
      r[root_b] = r[root_a];
      size[root_a] += size[root_b];
    }
  }
}
vector<vector<int> > jump, jumpc;
vector<int> height;
pair<int, int> ancestor(int i, int j) {
  int k = 0;
  int re = 0;
  while (j) {
    if (j & 1) {
      re = max(re, jumpc[i][k]);
      i = jump[i][k];
    }
    k++;
    j >>= 1;
  }
  return pair<int, int>(i, re);
}
int lca(int i, int j) {
  int hmin = 0, hmax = 1 + min(height[i], height[j]);
  while (hmax - hmin > 1) {
    int hmid = (hmax + hmin) / 2;
    pair<int, int> x = ancestor(i, height[i] - hmid);
    pair<int, int> y = ancestor(j, height[j] - hmid);
    if (x.first == y.first)
      hmin = hmid;
    else
      hmax = hmid;
  }
  return max(ancestor(i, height[i] - hmin).second,
             ancestor(j, height[j] - hmin).second);
}
void initialize(int root, const vector<vector<pair<int, int> > >& t) {
  int n = t.size();
  vector<int> pare(n), cpare(n);
  height = vector<int>(n, -1);
  stack<int> dfs;
  height[root] = 0;
  dfs.push(root);
  pare[root] = root;
  cpare[root] = 0;
  while (!dfs.empty()) {
    int p = dfs.top();
    dfs.pop();
    for (pair<int, int> f : t[p]) {
      if (height[f.second] < 0) {
        height[f.second] = height[p] + 1;
        pare[f.second] = p;
        cpare[f.second] = f.first;
        dfs.push(f.second);
      }
    }
  }
  int m = 1, maux = n;
  while (maux) {
    maux >>= 1;
    m++;
  }
  jumpc = jump = vector<vector<int> >(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    jump[i][0] = pare[i];
    jumpc[i][0] = cpare[i];
  }
  for (int j = 1; j < m; j++) {
    for (int i = 0; i < n; i++) {
      jump[i][j] = jump[jump[i][j - 1]][j - 1];
      jumpc[i][j] = max(jumpc[i][j - 1], jumpc[jump[i][j - 1]][j - 1]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int> > > g(n);
  vector<pair<pair<int, int>, pair<int, int> > > ed(m);
  for (int i = 0; i < m; i++) {
    int x, y, e;
    cin >> x >> y >> e;
    x--;
    y--;
    ed[i] = {pair<int, int>(e, i), pair<int, int>(x, y)};
    g[y].push_back({e, x});
    g[x].push_back({e, y});
  }
  sort(ed.begin(), ed.end());
  vector<int> r(n), mida(n, 1);
  for (int i = 0; i < n; i++) r[i] = i;
  vector<vector<pair<int, int> > > t(n);
  vector<int> pend;
  for (int i = 0; i < m; i++) {
    int x = ed[i].second.first, y = ed[i].second.second, e = ed[i].first.first;
    if (root(r, x) == root(r, y))
      pend.push_back(i);
    else {
      t[x].push_back({e, y});
      t[y].push_back({e, x});
      wunion(r, mida, x, y);
    }
  }
  initialize(0, t);
  vector<pair<int, int> > sol;
  for (int i : pend) {
    int x = ed[i].second.first, y = ed[i].second.second,
        ind = ed[i].first.second;
    sol.push_back({ind, lca(x, y)});
  }
  sort(sol.begin(), sol.end());
  for (auto x : sol) cout << x.second << "\n";
}