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 read() {
  long long cc = getc(stdin);
  for (; cc < '0' || cc > '9';) cc = getc(stdin);
  long long ret = 0;
  for (; cc >= '0' && cc <= '9';) {
    ret = ret * 10 + cc - '0';
    cc = getc(stdin);
  }
  return ret;
}
long long power(long long num, long long g) {
  if (g == 0) return 1;
  if (g % 2 == 1)
    return (num * power((num * num) % 998244353, g / 2)) % 998244353;
  return power((num * num) % 998244353, g / 2);
}
int parent[100005];
int siz[100005];
int find(int index) {
  if (parent[index] == index) return index;
  return parent[index] = find(parent[index]);
}
vector<pair<int, int> > vec[100005];
int b[100005][18], c[100005][18];
int timer, intime[100005], outtime[100005], level[100005];
void dfs(int index, int par, int lev) {
  level[index] = lev;
  timer++;
  intime[index] = timer;
  parent[index] = par;
  for (long long i = 0; i < vec[index].size(); i++) {
    if (vec[index][i].first == par) continue;
    c[vec[index][i].first][0] = vec[index][i].second;
    dfs(vec[index][i].first, index, lev + 1);
  }
  timer++;
  outtime[index] = timer;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  scanf("%d%d", &n, &m);
  pair<pair<int, int>, pair<int, int> > pa[m];
  vector<pair<int, int> > vec1;
  for (long long i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    pa[i] = make_pair(make_pair(w, i), make_pair(u, v));
  }
  sort(pa, pa + m);
  for (long long i = 0; i < n; i++) parent[i + 1] = i + 1, siz[i + 1] = 1;
  for (long long i = 0; i < m; i++) {
    int u = pa[i].second.first;
    int v = pa[i].second.second;
    int w = pa[i].first.first;
    int g = find(u);
    int h = find(v);
    if (g == h) continue;
    if (siz[g] > siz[h])
      siz[g] += siz[h], parent[h] = g;
    else
      siz[h] += siz[g], parent[g] = h;
    vec[u].push_back(make_pair(v, w));
    vec[v].push_back(make_pair(u, w));
  }
  timer = 0;
  dfs(1, 1, 1);
  for (long long i = 0; i < n; i++) {
    b[i + 1][0] = parent[i + 1];
  }
  for (int i = 1; i <= 17; i++) {
    for (int j = 1; j <= n; j++) {
      b[j][i] = b[b[j][i - 1]][i - 1];
      c[j][i] = max(c[j][i - 1], c[b[j][i - 1]][i - 1]);
    }
  }
  for (long long i = 0; i < n; i++) parent[i + 1] = i + 1, siz[i + 1] = 1;
  for (long long i = 0; i < m; i++) {
    int u = pa[i].second.first;
    int v = pa[i].second.second;
    int w = pa[i].first.first;
    int xyz = pa[i].first.second;
    int g = find(u);
    int h = find(v);
    if (g == h) {
      int g = 1 << 17;
      int ans = 0;
      int h = u;
      for (int j = 17; j >= 0; j--) {
        int d = b[h][j];
        if (intime[d] <= intime[v] && outtime[d] >= outtime[v]) {
          continue;
        }
        ans = max(ans, c[h][j]);
        h = d;
      }
      while (intime[h] > intime[v] || outtime[h] < outtime[v]) {
        ans = max(ans, c[h][0]);
        h = b[h][0];
      }
      h = v;
      for (int j = 17; j >= 0; j--) {
        int d = b[h][j];
        if (intime[d] <= intime[u] && outtime[d] >= outtime[u]) {
          continue;
        }
        ans = max(ans, c[h][j]);
        h = d;
      }
      while (intime[h] > intime[u] || outtime[h] < outtime[u]) {
        ans = max(ans, c[h][0]);
        h = b[h][0];
      }
      vec1.push_back(make_pair(xyz, ans));
      continue;
    }
    if (siz[g] > siz[h])
      siz[g] += siz[h], parent[h] = g;
    else
      siz[h] += siz[g], parent[g] = h;
    vec[u].push_back(make_pair(v, w));
    vec[v].push_back(make_pair(u, w));
  }
  sort(vec1.begin(), vec1.end());
  for (long long i = 0; i < vec1.size(); i++) printf("%d\n", vec1[i].second);
  return 0;
}