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>
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const int K = 18;
const long long INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
struct edge {
  int next, v, w;
} s[maxn << 1];
struct node {
  int u, v, w, i;
  bool operator<(const node& a) const { return w < a.w; }
};
bool cmp(const node& a, const node& b) { return a.i < b.i; }
int head[maxn], tot = 0;
int n, m, x, y, z, f[maxn], path[maxn], d[maxn], ma[maxn][18], fa[maxn][18];
deque<node> v, tree, q;
int find(int xx) { return f[xx] == -1 ? xx : f[xx] = find(f[xx]); }
void dfs(int now, int pre) {
  d[now] = d[pre] + 1;
  for (int i = 1; i < 18; ++i) {
    fa[now][i] = fa[fa[now][i - 1]][i - 1];
    ma[now][i] = max(ma[now][i - 1], ma[fa[now][i - 1]][i - 1]);
  }
  for (int i = head[now]; ~i; i = s[i].next) {
    int tv = s[i].v;
    if (tv == pre) continue;
    fa[tv][0] = now;
    ma[tv][0] = s[i].w;
    dfs(tv, now);
  }
}
void add(int u, int v, int w) {
  s[tot].v = v;
  s[tot].w = w;
  s[tot].next = head[u];
  head[u] = tot++;
}
int LCA(int x, int y) {
  int ans = -1;
  if (d[x] > d[y]) swap(x, y);
  int dd = d[y] - d[x];
  for (int i = 17; i >= 0; --i)
    if ((1 << i) & dd) {
      ans = max(ans, ma[y][i]);
      y = fa[y][i];
    }
  if (x == y) return ans;
  for (int i = 17; i >= 0; --i)
    if (fa[x][i] != fa[y][i]) {
      ans = max(ans, max(ma[x][i], ma[y][i]));
      x = fa[x][i];
      y = fa[y][i];
    }
  return max(ans, max(ma[x][0], ma[y][0]));
}
int main() {
  memset(head, -1, sizeof(head));
  memset(f, -1, sizeof(f));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    q.push_back(node({x, y, z, i}));
  }
  int cnt = 0;
  sort(q.begin(), q.end());
  while (!q.empty()) {
    node k = q.front();
    q.pop_front();
    int fx = find(k.u), fy = find(k.v);
    if (fx != fy) {
      f[fx] = fy;
      ++cnt;
      tree.push_back(k);
    } else
      v.push_back(k);
    if (cnt == n - 1) break;
  }
  while (!q.empty()) {
    v.push_back(q.front());
    q.pop_front();
  }
  for (int i = 0; i < tree.size(); i++) {
    add(tree[i].u, tree[i].v, tree[i].w);
    add(tree[i].v, tree[i].u, tree[i].w);
  }
  dfs(1, 0);
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < v.size(); i++) {
    printf("%d\n", (LCA(v[i].u, v[i].v)));
  }
}