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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) { return uniform_int_distribution<int>(0, x - 1)(rng); }
long long gcd(long long x, long long y) {
  if (x < y) return gcd(y, x);
  if (y == 0) return x;
  return gcd(y, x % y);
}
const long long mod = 2e5 + 7;
long long modexp(long long x, long long ex) {
  long long ans = 1ll;
  while (ex > 0) {
    if (ex & 1ll) ans = (ans * x) % mod;
    ex >>= 1ll;
    x = (x * x) % mod;
  }
  return ans;
}
const int maxn = 2e5 + 7;
const int lmx = 19;
const long long inf = 1e9 + 7;
int dsu[maxn];
vector<pair<pair<long long, long long>, pair<int, int> > > ed;
inline void unionS(int x, int y) { dsu[x] = y; }
int findS(int x) {
  if (dsu[x] < 0) return x;
  return (dsu[x] = findS(dsu[x]));
}
vector<pair<long long, long long> > G[maxn];
int dep[maxn];
int pi[maxn][lmx];
long long mx[maxn][lmx];
void dfs(int x, int p, long long w, int d) {
  pi[x][0] = p;
  mx[x][0] = w;
  dep[x] = d;
  for (int j = 1; j < lmx; j++) {
    if (pi[x][j - 1] < 0) {
      pi[x][j] = pi[x][j - 1];
      mx[x][j] = mx[x][j - 1];
    } else {
      pi[x][j] = pi[pi[x][j - 1]][j - 1];
      mx[x][j] = max(mx[x][j - 1], mx[pi[x][j - 1]][j - 1]);
    }
  }
  for (auto z : G[x]) {
    int y;
    long long w;
    tie(y, w) = z;
    if (y == p) continue;
    dfs(y, x, w, d + 1);
  }
}
long long pmx(int x, int y) {
  if (dep[x] > dep[y]) return pmx(y, x);
  long long ans = 0;
  for (int j = lmx - 1; j >= 0; j--) {
    if (pi[y][j] < 0 || dep[pi[y][j]] < dep[x]) continue;
    ans = max(ans, mx[y][j]);
    y = pi[y][j];
  }
  if (x == y) return ans;
  for (int j = lmx - 1; j >= 0; j--) {
    if (pi[x][j] < 0 || pi[y][j] < 0) continue;
    int a = pi[x][j], b = pi[y][j];
    if (a == b) continue;
    ans = max(ans, mx[x][j]);
    ans = max(ans, mx[y][j]);
    x = a;
    y = b;
  }
  if (x == y) return ans;
  ans = max(ans, mx[x][0]);
  ans = max(ans, mx[y][0]);
  return ans;
}
vector<pair<long long, long long> > ans;
int main() {
  {
    ios ::sync_with_stdio(false);
    cin.tie(0);
  };
  int n, m;
  cin >> n >> m;
  fill(dsu, dsu + maxn, -1);
  for (int j = 1; j <= m; j++) {
    int x, y;
    long long w;
    cin >> x >> y >> w;
    ed.push_back({{w, j}, {x, y}});
  }
  sort(ed.begin(), ed.end());
  for (int j = 0; j < ed.size(); j++) {
    auto z = ed[j];
    long long w = z.first.first;
    int x, y;
    tie(x, y) = z.second;
    int a = findS(x), b = findS(y);
    if (a == b) continue;
    unionS(a, b);
    G[a].push_back({b, w});
    G[b].push_back({a, w});
    ed[j].first.second = -1;
  }
  dfs(1, -1, 0, 0);
  for (auto z : ed) {
    if (z.first.second < 0) continue;
    int x, y;
    tie(x, y) = z.second;
    ans.push_back({z.first.second, pmx(x, y)});
  }
  sort(ans.begin(), ans.end());
  for (auto z : ans) {
    cout << z.second << "\n";
  }
}