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;
long long inf = 4e18, mod = 1e9 + 7;
vector<vector<int>> notused;
int dsu[100005], siz[100005], tin[100005], tout[100005], hgt[100005];
vector<vector<int>> maxup, up;
int l, timer;
vector<pair<long long, long long>> node[100005];
void init() {
  for (int i = 1; i <= 100000; i++) dsu[i] = i, siz[i] = 1;
}
int find_parent(int x) { return dsu[x] == x ? x : find_parent(dsu[x]); }
void merge(int x, int y, int z, int id) {
  int nx = find_parent(x);
  int ny = find_parent(y);
  if (nx == ny) {
    notused.push_back({id, x, y});
    return;
  }
  if (siz[nx] < siz[ny]) swap(nx, ny);
  siz[nx] += siz[ny];
  dsu[ny] = nx;
  node[x].push_back({y, z});
  node[y].push_back({x, z});
}
void dfs(int x, int p, int w) {
  maxup[x][0] = w;
  up[x][0] = p;
  tin[x] = ++timer;
  hgt[x] = hgt[p] + 1;
  for (int i = 1; i <= l; i++) {
    up[x][i] = up[up[x][i - 1]][i - 1];
  }
  for (int i = 1; i <= l; i++) {
    maxup[x][i] = max(maxup[x][i - 1], maxup[up[x][i - 1]][i - 1]);
  }
  for (auto it : node[x]) {
    if (it.first != p) {
      dfs(it.first, x, it.second);
    }
  }
  tout[x] = ++timer;
}
bool is_ancestor(int u, int v) {
  if (tin[u] <= tin[v] && tout[u] >= tout[v]) return 1;
  return 0;
}
int lca(int u, int v) {
  if (is_ancestor(u, v)) return u;
  if (is_ancestor(v, u)) return v;
  for (int i = l; i >= 0; i--) {
    if (!is_ancestor(up[u][i], v)) {
      u = up[u][i];
    }
  }
  return up[u][0];
}
void solve() {
  int n, m;
  cin >> n >> m;
  init();
  set<pair<pair<long long, long long>, pair<long long, long long>>> s;
  for (int i = 1; i <= m; i++) {
    int u, v, z;
    cin >> u >> v >> z;
    s.insert({{z, i}, {u, v}});
  }
  int cnt = n - 1;
  while (!s.empty()) {
    auto it = s.begin();
    pair<pair<long long, long long>, pair<long long, long long>> p = *it;
    s.erase(it);
    int x = p.second.first, y = p.second.second, z = p.first.first,
        id = p.first.second;
    merge(x, y, z, id);
  }
  l = log2(n + 1);
  maxup.resize(n + 1, vector<int>(l + 1, 0));
  up.resize(n + 1, vector<int>(l + 1, 0));
  dfs(1, 1, 0);
  sort(notused.begin(), notused.end());
  for (auto it : notused) {
    int u = it[1], v = it[2];
    int L = lca(u, v);
    int mx = 0;
    int d1 = hgt[u] - hgt[L], d2 = hgt[v] - hgt[L];
    for (int i = 0; i <= l; i++) {
      if (d1 & (1LL << i)) {
        mx = max(mx, maxup[u][i]);
        u = up[u][i];
      }
      if (d2 & (1LL << i)) {
        mx = max(mx, maxup[v][i]);
        v = up[v][i];
      }
    }
    cout << mx << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
}