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 inf = 0x3f3f3f3f, maxN = 1e6 + 5;
int N, M, T, bian, bing[maxN];
int seg[maxN];
int fond(int u) { return bing[u] == u ? u : bing[u] = fond(bing[u]); }
void push_up(int rt) { seg[rt] = max(seg[rt << 1], seg[rt << 1 | 1]); }
void build(int l, int r, int rt) {
  seg[rt] = 0;
  if (l == r) return;
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
}
int query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) return seg[rt];
  int m = (l + r) >> 1;
  int ret = 0;
  if (L <= m) ret = max(ret, query(L, R, l, m, rt << 1));
  if (R > m) ret = max(ret, query(L, R, m + 1, r, rt << 1 | 1));
  return ret;
}
void update(int p, int x, int l, int r, int rt) {
  if (l == r) {
    seg[rt] = x;
    return;
  }
  int m = (r + l) >> 1;
  if (p <= m)
    update(p, x, l, m, rt << 1);
  else
    update(p, x, m + 1, r, rt << 1 | 1);
  push_up(rt);
}
struct Edge {
  int to, next;
} edge[maxN];
int head[maxN], tot;
int top[maxN];
int fa[maxN];
int deep[maxN];
int num[maxN];
int p[maxN];
int fp[maxN];
int son[maxN];
int pos;
void init() {
  tot = 0;
  pos = 0;
  memset(head, -1, sizeof(head));
  memset(son, -1, sizeof(son));
}
void addEdge(int u, int v) {
  edge[tot].to = v;
  edge[tot].next = head[u];
  head[u] = tot++;
}
void dfs1(int u, int pre, int d) {
  deep[u] = d;
  fa[u] = pre;
  num[u] = 1;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v != pre) {
      dfs1(v, u, d + 1);
      num[u] += num[v];
      if (son[u] == -1 || num[v] > num[son[u]]) son[u] = v;
    }
  }
}
void getPos(int u, int sp) {
  top[u] = sp;
  p[u] = pos++;
  fp[p[u]] = u;
  if (son[u] == -1) return;
  getPos(son[u], sp);
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v != son[u] && v != fa[u]) getPos(v, v);
  }
}
int findMax(int u, int v) {
  int f1 = top[u], f2 = top[v];
  int tmp = 0;
  while (f1 != f2) {
    if (deep[f1] < deep[f2]) {
      swap(f1, f2);
      swap(u, v);
    }
    tmp = max(tmp, query(p[f1], p[u], 0, pos - 1, 1));
    u = fa[f1];
    f1 = top[u];
  }
  if (u == v) return tmp;
  if (deep[u] > deep[v]) swap(u, v);
  return max(tmp, query(p[son[u]], p[v], 0, pos - 1, 1));
}
struct node {
  int u, v, w, id;
  bool operator<(const node &b) const { return w < b.w; }
} e[maxN];
bool book[maxN];
int sumq = 0;
bool cmp(node aa, node bb) { return aa.id < bb.id; }
int main() {
  init();
  scanf("%d%d", &N, &bian);
  for (int i = 1; i <= N; i++) bing[i] = i;
  for (int i = 1; i <= bian; i++) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
    e[i].id = i;
  }
  sort(e + 1, e + 1 + bian);
  for (int i = 1; i <= bian; i++) {
    int uu = fond(e[i].u);
    int vv = fond(e[i].v);
    if (uu == vv) continue;
    book[e[i].id] = 1;
    bing[uu] = vv;
    addEdge(e[i].u, e[i].v);
    addEdge(e[i].v, e[i].u);
    sumq++;
    if (sumq == N - 1) break;
  }
  sort(e + 1, e + 1 + bian, cmp);
  dfs1(1, 0, 0);
  getPos(1, 1);
  build(0, pos - 1, 1);
  for (int i = 1; i <= bian; i++) {
    if (book[i] == 0) continue;
    if (deep[e[i].u] > deep[e[i].v]) swap(e[i].u, e[i].v);
    update(p[e[i].v], e[i].w, 0, pos - 1, 1);
  }
  for (int i = 1; i <= bian; i++)
    if (book[i] == 0) printf("%d\n", findMax(e[i].u, e[i].v));
  return 0;
}