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;
const int MAXN = 1e5 + 5;
struct Edge {
  int u, v, w;
  Edge() {}
  Edge(int _u, int _v, int _w) : u(_u), v(_v), w(_w) {}
};
bool cmp(Edge a, Edge b) { return (a.w < b.w); }
int n, m;
vector<Edge> e, originE;
vector<pair<int, int> > adj[MAXN];
pair<int, int> st[MAXN][21];
int d[MAXN], p[MAXN];
class DSU {
  int sz;
  vector<int> p;

 public:
  DSU() {}
  DSU(int _sz) : sz(_sz) {
    p.resize(sz + 1);
    for (int i = 0; i <= sz; ++i) {
      p[i] = i;
    }
  }
  int getParent(int x) {
    if (p[x] == x)
      return x;
    else
      return p[x] = getParent(p[x]);
  }
  void conn(int a, int b) {
    int pa = getParent(a), pb = getParent(b);
    if (pa != pb) {
      p[pa] = pb;
    }
  }
} dsu;
void buildTree(int pos, int depth) {
  d[pos] = depth;
  for (pair<int, int> i : adj[pos])
    if (p[pos] != i.first) {
      p[i.first] = pos;
      st[i.first][0] = pair<int, int>(p[i.first], i.second);
      buildTree(i.first, depth + 1);
    }
}
void buildST() {
  for (int j = 1; j < 20; ++j) {
    for (int i = 1; i <= n; ++i) {
      if (st[i][j - 1].first == -1) {
        st[i][j].first = -1;
        st[i][j].second = st[i][j - 1].second;
      } else {
        st[i][j].first = st[st[i][j - 1].first][j - 1].first;
        st[i][j].second =
            max(st[i][j - 1].second, st[st[i][j - 1].first][j - 1].second);
      }
    }
  }
}
pair<int, int> getLCA(int a, int b) {
  int maxW = 0;
  if (d[a] < d[b]) swap(a, b);
  for (int i = 19; i >= 0; --i) {
    if (d[a] - (1 << i) >= d[b]) {
      maxW = max(maxW, st[a][i].second);
      a = st[a][i].first;
    }
  }
  if (a == b) return pair<int, int>(a, maxW);
  for (int i = 19; i >= 0; --i) {
    if (st[a][i].first != st[b][i].first) {
      maxW = max(maxW, st[a][i].second);
      maxW = max(maxW, st[b][i].second);
      a = st[a][i].first;
      b = st[b][i].first;
    }
  }
  maxW = max(maxW, max(st[a][0].second, st[b][0].second));
  return pair<int, int>(a, maxW);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < MAXN; ++i) {
    for (int j = 0; j < 20; ++j) {
      st[i][j] = pair<int, int>(-1, 0);
    }
  }
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    e.push_back(Edge(u, v, w));
    originE.push_back(Edge(u, v, w));
  }
  sort(e.begin(), e.end(), cmp);
  dsu = DSU(n);
  for (Edge i : e) {
    if (dsu.getParent(i.u) != dsu.getParent(i.v)) {
      dsu.conn(i.u, i.v);
      adj[i.u].push_back(pair<int, int>(i.v, i.w));
      adj[i.v].push_back(pair<int, int>(i.u, i.w));
    }
  }
  buildTree(1, 0);
  buildST();
  for (Edge i : originE) {
    if (p[i.u] == i.v || p[i.v] == i.u) continue;
    printf("%d\n", getLCA(i.u, i.v).second);
  }
}