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;
inline long long gcd(long long a, long long b) {
  while (b != 0) {
    long long c = a % b;
    a = b;
    b = c;
  }
  return a < 0 ? -a : a;
}
inline long long lowbit(long long x) { return x & (-x); }
const double PI = 3.14159265358979323846;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long mod = 100000007;
inline long long rd() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const double eps = 1e-6;
const int M = 1e6 + 10;
const int N = 1e5 + 10;
int ffa[N];
int find(int x) { return x == ffa[x] ? x : ffa[x] = find(ffa[x]); }
struct Edge {
  int to, next;
  int w;
} e[N << 1];
struct edge {
  int id, w, u, v, fg;
  bool friend operator<(const edge& m1, const edge& m2) { return m1.w < m2.w; }
} em[M];
int head[N], tot;
void add(int x, int y, int w) {
  e[++tot] = {y, head[x], w};
  head[x] = tot;
}
int n, m;
int d[N], siz[N], son[N], top[N], fa[N], dfn[N];
int b[N], a[N];
void dfs1(int x, int dep) {
  d[x] = dep, siz[x] = 1, son[x] = -1;
  for (int i = head[x]; i != -1; i = e[i].next) {
    int y = e[i].to;
    if (d[y]) continue;
    fa[y] = x;
    b[y] = e[i].w;
    dfs1(y, dep + 1);
    siz[x] += siz[y];
    if (son[x] == -1 || siz[son[x]] < siz[y]) son[x] = y;
  }
}
int num;
void dfs2(int x, int t) {
  dfn[x] = ++num, top[x] = t;
  if (son[x] == -1) return;
  dfs2(son[x], t);
  for (int i = head[x]; i != -1; i = e[i].next) {
    int y = e[i].to;
    if (y == son[x] || y == fa[x]) continue;
    dfs2(y, y);
  }
}
int f[N][25];
void ST_prework1() {
  for (int i = 1; i <= n; i++) f[i][0] = a[i];
  int t = (int)(log(n) / log(2)) + 1;
  for (int j = 1; j < t; j++) {
    for (int i = 1; i <= n - (1 << j) + 1; i++) {
      f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int query(int l, int r) {
  if (l > r) return 0;
  int k = log(r - l + 1) / log(2);
  return max(f[l][k], f[r - (1 << k) + 1][k]);
}
int get(int x, int y) {
  int maxx = 0;
  while (top[x] != top[y]) {
    if (d[top[x]] < d[top[y]]) swap(x, y);
    maxx = max(maxx, query(dfn[top[x]], dfn[x]));
    x = fa[top[x]];
  }
  if (d[x] < d[y]) swap(x, y);
  maxx = max(maxx, query(dfn[y] + 1, dfn[x]));
  return maxx;
}
void init() {
  num = tot = 0;
  memset(head, -1, sizeof(int) * (n + 10));
}
int ans[M];
int main() {
  n = rd(), m = rd();
  init();
  for (int i = 1; i <= m; i++) {
    em[i].u = rd(), em[i].v = rd(), em[i].w = rd();
    em[i].id = i;
  }
  for (int i = 1; i <= n; i++) ffa[i] = i;
  sort(em + 1, em + 1 + m);
  for (int i = 1; i <= m; i++) {
    if (find(em[i].u) == find(em[i].v)) continue;
    add(em[i].u, em[i].v, em[i].w);
    add(em[i].v, em[i].u, em[i].w);
    em[i].fg = 1;
    ffa[find(em[i].u)] = find(em[i].v);
  }
  dfs1(1, 1);
  dfs2(1, 1);
  for (int i = 1; i <= n; i++) {
    a[dfn[i]] = b[i];
  }
  ST_prework1();
  memset(ans, -1, sizeof ans);
  for (int i = 1; i <= m; i++) {
    if (em[i].fg) continue;
    ans[em[i].id] = get(em[i].u, em[i].v);
  }
  for (int i = 1; i <= m; i++) {
    if (ans[i] != -1) printf("%d\n", ans[i]);
  }
}