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 void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
inline void writes(string s) { puts(s.c_str()); }
inline void writeln() { writes(""); }
inline void writei(int x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
inline void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
int n, m, i, j, fa[100005], vis[1000005], l, r, mid, ans, p[100005][19],
    mx[100005][19], dep[100005];
struct edg {
  int x, y, z, id;
} a[1000005], b[1000005];
vector<pair<int, int> > e[100005];
bool cmp(edg x, edg y) {
  if (x.z == y.z) return x.id < y.id;
  return x.z < y.z;
}
int fnd(int x) {
  if (fa[x] == x) return x;
  return fa[x] = fnd(fa[x]);
}
void dfs(int x, int pp) {
  p[x][0] = pp;
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++)
    if (it->first != pp) {
      dep[it->first] = dep[x] + 1;
      mx[it->first][0] = it->second;
      dfs(it->first, x);
    }
}
int qry(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int t = dep[x] - dep[y], i, ans = 0;
  for ((i) = (18); (i) >= (0); (i)--)
    if ((t >> i) & 1) {
      ans = max(ans, mx[x][i]);
      x = p[x][i];
    }
  if (x == y) return ans;
  for ((i) = (18); (i) >= (0); (i)--)
    if (p[x][i] != p[y][i]) {
      ans = max(ans, max(mx[x][i], mx[y][i]));
      x = p[x][i];
      y = p[y][i];
    }
  return max(ans, max(mx[x][0], mx[y][0]));
}
int main() {
  read(n);
  read(m);
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) {
    read(a[i].x);
    read(a[i].y);
    read(a[i].z);
    a[i].id = i;
  }
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) b[i] = a[i];
  sort(b + 1, b + m + 1, cmp);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) fa[i] = i;
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) {
    if (fnd(b[i].x) != fnd(b[i].y)) {
      fa[fnd(b[i].x)] = fnd(b[i].y);
      vis[b[i].id] = 1;
      e[b[i].x].push_back(make_pair(b[i].y, b[i].z));
      e[b[i].y].push_back(make_pair(b[i].x, b[i].z));
    }
  }
  dfs(1, 0);
  for (((j)) = (1); ((j)) <= ((18)); ((j))++)
    for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
      p[i][j] = p[p[i][j - 1]][j - 1];
      mx[i][j] = max(mx[i][j - 1], mx[p[i][j - 1]][j - 1]);
    }
  for (((i)) = (1); ((i)) <= ((m)); ((i))++)
    if (!vis[i]) {
      printf("%d\n", qry(a[i].x, a[i].y));
    }
  return 0;
}