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 double eps = 1e-10;
const int maxn = 1000000 + 9;
const double pi = 3.14159265358979323846264338328;
const int inf = int(1e9);
int pq[maxn], jk[maxn];
int fg(int p) {
  if (pq[p] == p)
    return p;
  else
    return pq[p] = fg(pq[p]);
}
void unite(int x, int y) {
  x = fg(x);
  y = fg(y);
  if (x == y) return;
  if (jk[x] < jk[y]) {
    pq[x] = y;
  } else {
    pq[y] = x;
    if (jk[x] == jk[y]) jk[x]++;
  }
}
bool same(int x, int y) {
  if (fg(x) == fg(y))
    return true;
  else
    return false;
}
struct edge {
  int u, v, cost, id;
};
bool cmp(const edge &a, const edge &b) {
  if (a.cost != b.cost) return a.cost < b.cost;
  return a.id < b.id;
}
int n, m, vis[maxn], kl[maxn];
edge op[maxn], io[maxn];
void sol() {
  memset(jk, 0, sizeof(jk));
  for (int i = 1; i <= n; ++i) pq[i] = i;
  for (int i = 1; i <= n; ++i) kl[i] = inf;
  sort(op, op + m, cmp);
  int num = 0;
  for (int i = 0; i < m; ++i) {
    if (!same(op[i].u, op[i].v)) {
      vis[op[i].id] = 1;
      unite(op[i].u, op[i].v);
      ++num;
      if (num == n - 1) break;
    }
  }
}
vector<pair<int, int> > g[maxn];
int parent[20][int(1e5) + 9], gh[20][int(1e5) + 9], depth[int(1e5) + 9];
void dfs(int u, int v, int d, int w) {
  parent[0][u] = v;
  depth[u] = d;
  gh[0][u] = w;
  for (int i = 0; i < g[u].size(); ++i) {
    pair<int, int> e = g[u][i];
    if (e.first != v) dfs(e.first, u, d + 1, e.second);
  }
}
void init(int n) {
  dfs(1, -1, 0, -1);
  for (int i = 1; i < 20; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (parent[i - 1][j] < 0)
        parent[i][j] = gh[i][j] = -1;
      else {
        int v = parent[i - 1][j];
        gh[i][j] = max(gh[i - 1][j], gh[i - 1][v]);
        parent[i][j] = parent[i - 1][v];
      }
    }
  }
}
int sol(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  int ans = -1;
  for (int i = 0; i < 20; ++i) {
    if ((depth[v] - depth[u]) >> i & 1) {
      ans = max(ans, gh[i][v]);
      v = parent[i][v];
    }
  }
  if (u == v) return ans;
  for (int i = 19; i >= 0; --i) {
    if (parent[i][u] != parent[i][v]) {
      ans = max(gh[i][u], ans);
      ans = max(ans, gh[i][v]);
      u = parent[i][u];
      v = parent[i][v];
    }
  }
  return max(max(ans, gh[0][u]), gh[0][v]);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i)
    scanf("%d%d%d", &op[i].u, &op[i].v, &op[i].cost), op[i].id = i,
                                                      io[i] = op[i];
  sol();
  for (int i = 0; i < m; ++i) {
    if (vis[i]) {
      int u = io[i].u, v = io[i].v;
      g[u].push_back(make_pair(v, io[i].cost));
      g[v].push_back(make_pair(u, io[i].cost));
    }
  }
  init(n);
  for (int i = 0; i < m; ++i) {
    if (!vis[i]) {
      int u = io[i].u, v = io[i].v;
      printf("%d\n", sol(u, v));
    }
  }
  return 0;
}