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;
class trio {
 public:
  long long first, second, third;
};
class quad {
 public:
  long long first, second, third, fourth;
};
class DSU {
 public:
  long long *par, *size;
  DSU(long long n) {
    par = new long long[n + 1];
    size = new long long[n + 1];
    for (long long i = 0; i < n + 1; ++i) {
      par[i] = i;
      size[i] = 0;
    }
  }
  long long find(long long a) {
    long long p = a, third;
    while (par[p] != p) p = par[p];
    while (p != a) {
      third = par[a];
      par[a] = p;
      a = third;
    }
    return a;
  }
  void union_(long long a, long long b) {
    long long u1 = find(a);
    long long u2 = find(b);
    if (size[u1] < size[u2]) {
      par[u1] = u2;
    } else {
      if (size[u2] < size[u1]) {
        par[u2] = u1;
      } else {
        par[u1] = u2;
        size[u1]++;
      }
    }
  }
};
bool mycom(quad a, quad b) { return a.first < b.first; }
long long *intime, *outime, timt = 1;
bool inacestor(long long a, long long b) {
  return (intime[a] <= intime[b] && outime[a] >= outime[b]);
}
long long tree[100010][20];
long long dp[100010][20];
void dfs(long long i, list<pair<long long, long long> > *adj) {
  intime[i] = timt;
  timt++;
  for (auto it : adj[i]) {
    if (it.first != tree[i][0]) {
      tree[it.first][0] = i;
      dp[it.first][0] = it.second;
      dfs(it.first, adj);
    }
  }
  outime[i] = timt;
  timt++;
}
long long func(long long a, long long b) {
  long long ans = 0;
  for (long long j = 19; j >= 0; --j) {
    if (inacestor(tree[a][j], b)) continue;
    ans = max(ans, dp[a][j]);
    a = tree[a][j];
  }
  for (long long j = 19; j >= 0; --j) {
    if (inacestor(tree[b][j], a)) continue;
    ans = max(ans, dp[b][j]);
    b = tree[b][j];
  }
  if (!inacestor(a, b) && !inacestor(b, a)) {
    ans = max(ans, dp[b][0]);
    ans = max(ans, dp[a][0]);
  } else {
    if (inacestor(a, b)) {
      ans = max(ans, dp[b][0]);
    } else
      ans = max(ans, dp[a][0]);
  }
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, m;
  cin >> n >> m;
  quad edges[m + 1];
  bool select[m + 1];
  memset(select, 0, sizeof(select));
  for (long long i = 0; i < m; ++i) {
    cin >> edges[i].second >> edges[i].third >> edges[i].first;
    edges[i].fourth = i;
  }
  sort(edges, edges + m, mycom);
  DSU dsu1(n);
  long long ans[m + 1];
  for (long long i = 0; i < m; ++i) {
    ans[i] = -1;
  }
  list<pair<long long, long long> > adj[n + 1];
  for (long long i = 0; i < m; ++i) {
    if (dsu1.find(edges[i].second) != dsu1.find(edges[i].third)) {
      dsu1.union_(edges[i].second, edges[i].third);
      select[i] = 1;
      adj[edges[i].second].push_back({edges[i].third, edges[i].first});
      adj[edges[i].third].push_back({edges[i].second, edges[i].first});
    }
  }
  intime = new long long[n + 1];
  outime = new long long[n + 1];
  tree[1][0] = -1;
  dfs(1, adj);
  tree[1][0] = 1;
  dp[1][0] = 0;
  for (long long j = 1; j < 20; ++j) {
    for (long long i = 1; i < n + 1; ++i) {
      tree[i][j] = tree[tree[i][j - 1]][j - 1];
      dp[i][j] = max(dp[tree[i][j - 1]][j - 1], dp[i][j - 1]);
    }
  }
  for (long long j = 0; j < m; ++j) {
    if (select[j] == 0) {
      ans[edges[j].fourth] = func(edges[j].second, edges[j].third);
    }
  }
  for (long long i = 0; i < m; ++i) {
    if (ans[i] != -1) {
      cout << ans[i] << endl;
    }
  }
}