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;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
constexpr auto MOD = 1000000007LL;
constexpr auto LINF = (1LL << 60);
constexpr auto INF = 1000000000LL;
constexpr auto PI = 3.1415926535897932384626433;
constexpr auto EPS = 1E-9;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> p) {
  out << p.first << ' ' << p.second;
  return out;
}
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (auto &x : v) in >> x;
  return in;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> v) {
  for (int i = 0; i < v.size(); i++)
    out << v[i] << (i + 1 == v.size() ? '\n' : ' ');
  out.flush();
  return out;
}
struct node {
  node *l, *r, *par;
  bool rev;
  int val, mx;
  node() { val = mx = 0; }
};
node T[100010 + 1000010];
inline void reverse(node *x) {
  if (x) {
    x->rev ^= 1;
    swap(x->l, x->r);
  }
  return;
}
void maintain(node *x) {
  if (x) {
    x->mx = x->val;
    if (x->l) {
      x->mx = max(x->mx, x->l->mx);
    }
    if (x->r) {
      x->mx = max(x->mx, x->r->mx);
    }
  }
  return;
}
inline bool isroot(node *x) {
  if (not x->par) return true;
  return x->par->l != x && x->par->r != x;
}
inline void push(node *x) {
  if (x) {
    if (x->rev) reverse(x->l), reverse(x->r);
    x->rev = false;
  }
  return;
}
inline void getpushed(node *x) {
  if (not isroot(x)) getpushed(x->par);
  push(x);
}
void rotate(node *x) {
  node *y = x->par;
  node *z = y->par;
  if (not isroot(y)) {
    if (z->l == y) z->l = x;
    if (z->r == y) z->r = x;
  }
  x->par = z;
  if (y->r == x) {
    if (y->r = x->l) y->r->par = y;
    y->par = x;
    x->l = y;
  } else {
    if (y->l = x->r) y->l->par = y;
    y->par = x;
    x->r = y;
  }
  maintain(y), maintain(x), maintain(z);
  return;
}
inline void splay(node *x) {
  getpushed(x);
  while (not isroot(x)) {
    node *y = x->par;
    if (not isroot(y)) {
      node *z = y->par;
      if ((z->l == y) ^ (y->l == x))
        rotate(x);
      else
        rotate(y);
    }
    rotate(x);
  }
  return;
}
inline node *access(node *x) {
  node *ret = NULL;
  while (x) {
    splay(x);
    x->r = ret;
    maintain(x);
    ret = x;
    x = x->par;
  }
  return ret;
}
inline void makeroot(node *x) {
  access(x);
  splay(x);
  reverse(x);
  return;
}
inline void link(node *x, node *y) {
  makeroot(x);
  x->par = y;
  return;
}
inline void cut(node *x, node *y) {
  makeroot(x);
  access(y);
  splay(y);
  y->l = NULL;
  x->par = NULL;
  return;
}
inline bool connected(node *x, node *y) {
  makeroot(x);
  access(y);
  splay(x);
  node *t = y;
  while (t->par) t = t->par;
  return t == x;
}
int n, m;
pii a[1000010];
int w[1000010], ord[1000010], isin[1000010];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> w[i];
    if (i > 0) {
      T[i + n].val = T[i + n].mx = w[i];
    }
    ord[i] = i;
  }
  sort(ord + 1, ord + m + 1, [](int x, int y) { return w[x] < w[y]; });
  for (int i = 1, cnt = 0; i <= m; i++) {
    int j = ord[i];
    auto [u, v] = a[j];
    if (!connected(T + u, T + v)) {
      link(T + u, T + n + j);
      link(T + v, T + n + j);
      isin[j] = 1;
      if (++cnt == n - 1) break;
    }
  }
  for (int j = 1; j <= m; j++) {
    if (isin[j]) continue;
    int res = 1e9;
    auto [u, v] = a[j];
    if (connected(T + u, T + v)) {
      makeroot(T + u);
      access(T + v);
      res = T[v].mx;
    }
    cout << res << endl;
  }
  return 0;
}