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;
template <class T>
void chkmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void chkmin(T &a, T b) {
  if (a > b) a = b;
}
int rt[100005];
int find_rt(int first) {
  if (rt[first] == first) return first;
  return rt[first] = find_rt(rt[first]);
}
int n, m;
vector<pair<int, int> > v[100005];
int st[1000005], fs[1000005], ww[1000005];
int id[1000005], ID[100005];
bool vis[1000005];
int mx[100005][17];
int p[100005][17], dp[100005], mn[100005][17];
const int inf = 1e9;
void dfs(int k, int pa, int id) {
  p[k][0] = pa;
  mx[k][0] = ww[id];
  ID[k] = id;
  dp[k] = dp[pa] + 1;
  for (int i = 1; i <= 16; i++) {
    p[k][i] = p[p[k][i - 1]][i - 1];
    mx[k][i] = max(mx[k][i - 1], mx[p[k][i - 1]][i - 1]);
  }
  for (int i = 0; i <= 16; i++) mn[k][i] = inf;
  for (auto first : v[k]) {
    if (first.first == pa) continue;
    dfs(first.first, k, first.second);
  }
  return;
}
int lca(int first, int second, int z) {
  if (dp[first] > dp[second]) swap(first, second);
  int res = 0;
  for (int i = 16; i >= 0; i--)
    if (dp[second] - dp[first] >= (1 << i)) {
      chkmin(mn[second][i], z);
      chkmax(res, mx[second][i]);
      second = p[second][i];
    }
  if (first == second) return res;
  for (int i = 16; i >= 0; i--)
    if (p[second][i] != p[first][i]) {
      chkmin(mn[second][i], z);
      chkmax(res, mx[second][i]);
      chkmin(mn[first][i], z);
      chkmax(res, mx[first][i]);
      first = p[first][i], second = p[second][i];
    }
  chkmin(mn[second][0], z), chkmin(mn[first][0], z);
  chkmax(res, mx[first][0]), chkmax(res, mx[second][0]);
  return res;
}
int ans[1000005];
bool cmp(int first, int second) { return ww[first] < ww[second]; }
int main() {
  scanf("%d %d", &n, &m);
  int eg = 0;
  for (int i = 1; i <= n; i++) rt[i] = i;
  for (int i = 1; i <= m; i++) {
    int first, second, z;
    scanf("%d %d %d", &st[i], &fs[i], &ww[i]);
    id[i] = i;
  }
  sort(id + 1, id + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    int k = id[i];
    int first = st[k], second = fs[k], z = ww[k];
    int rx = find_rt(first), ry = find_rt(second);
    if (rx == ry) continue;
    rt[rx] = ry;
    vis[k] = 1;
    eg++;
    v[first].push_back(pair<int, int>(second, k));
    v[second].push_back(pair<int, int>(first, k));
  }
  dfs(1, 0, 0);
  for (int i = 1; i <= m; i++)
    if (!vis[i]) {
      int first = st[i], second = fs[i];
      ans[i] = lca(first, second, ww[i]);
    }
  for (int i = 16; i >= 1; i--) {
    for (int j = 1; j <= n; j++) {
      chkmin(mn[j][i - 1], mn[j][i]);
      chkmin(mn[p[j][i - 1]][i - 1], mn[j][i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    ans[ID[i]] = mn[i][0];
  }
  for (int i = 1; i <= m; i++)
    if (!vis[i]) printf("%d\n", ans[i]);
  return 0;
}