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 = 1000005;
int dep[Maxn], maxi[Maxn][23], anc[Maxn][23], cnt, head[Maxn], n, m, fa[Maxn];
bool choose[Maxn];
int get_fa(int x) { return x == fa[x] ? x : fa[x] = get_fa(fa[x]); }
void merge(int x, int y) {
  int a = get_fa(x), b = get_fa(y);
  fa[a] = b;
}
struct Edg {
  int x, y, w, id;
  bool operator<(const Edg &tmp) const { return w < tmp.w; }
} Edge[Maxn];
struct edg {
  int nxt, to, w;
} edge[Maxn];
void add(int x, int y, int w) {
  edge[++cnt] = (edg){head[x], y, w};
  head[x] = cnt;
}
void kruskal(void) {
  for (int i = 1; i <= n; i++) fa[i] = i;
  sort(Edge + 1, Edge + 1 + m);
  for (int i = 1; i <= m; i++) {
    int x = Edge[i].x, y = Edge[i].y;
    if (get_fa(x) != get_fa(y)) {
      merge(x, y);
      choose[i] = true;
      add(x, y, Edge[i].w);
      add(y, x, Edge[i].w);
    }
  }
}
void dfs(int u, int fa) {
  anc[u][0] = fa;
  for (int i = head[u]; i; i = edge[i].nxt) {
    int to = edge[i].to;
    if (to != fa) {
      maxi[to][0] = edge[i].w;
      dep[to] = dep[u] + 1;
      dfs(to, u);
    }
  }
}
void init(void) {
  for (int i = 1; (1 << i) <= n; i++)
    for (int j = 1; j <= n; j++) {
      anc[j][i] = anc[anc[j][i - 1]][i - 1];
      maxi[j][i] = max(maxi[j][i - 1], maxi[anc[j][i - 1]][i - 1]);
    }
}
int lca(int x, int y) {
  int ans = 0;
  if (dep[x] < dep[y]) swap(x, y);
  int diff = dep[x] - dep[y];
  for (int i = log2(n); i >= 0; i--)
    if (diff & (1 << i)) ans = max(ans, maxi[x][i]), x = anc[x][i];
  if (x == y) return ans;
  for (int i = log2(n); i >= 0; i--) {
    if (anc[x][i] != anc[y][i]) {
      ans = max(ans, max(maxi[x][i], maxi[y][i]));
      x = anc[x][i];
      y = anc[y][i];
    }
  }
  return max(ans, max(maxi[x][0], maxi[y][0]));
}
int ans[Maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d", &Edge[i].x, &Edge[i].y, &Edge[i].w), Edge[i].id = i;
  kruskal();
  dfs(1, 0);
  init();
  for (int i = 1; i <= m; i++)
    if (!choose[i]) ans[Edge[i].id] = lca(Edge[i].x, Edge[i].y);
  for (int i = 1; i <= m; i++)
    if (ans[i]) printf("%d\n", ans[i]);
  return 0;
}