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;
const int max_n = 100111, max_e = 1000011, inf = 1000111222;
int pr[max_n];
int sz[max_n];
int n, m;
vector<pair<pair<int, int>, pair<int, int>>> f;
vector<pair<pair<int, int>, pair<int, int>>> e;
vector<pair<pair<int, int>, pair<int, int>>> alle;
int get_set(int cur) { return pr[cur] == cur ? cur : cur = get_set(pr[cur]); }
void unite(int a, int b) {
  int pa = get_set(a);
  int pb = get_set(b);
  if (sz[pa] > sz[pb]) {
    pr[pb] = pa;
    sz[pa] += sz[pb];
  } else {
    pr[pa] = pb;
    sz[pb] += sz[pa];
  }
}
void clr() {
  for (int i = 0; i < n; ++i) {
    pr[i] = i;
    sz[i] = 1;
  }
}
int l[max_e], r[max_e], mid[max_e];
int ans[max_e];
bool res[max_e];
void split() {
  clr();
  for (auto c : alle) {
    int a = c.second.first, b = c.second.second;
    bool added;
    if (get_set(a) != get_set(b)) {
      added = true;
      unite(a, b);
    } else {
      added = false;
    }
    if (added) {
      e.push_back(c);
    } else {
      f.push_back(c);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    pair<pair<int, int>, pair<int, int>> c;
    scanf("%d%d%d", &c.second.first, &c.second.second, &c.first.first);
    --c.second.second;
    --c.second.first;
    c.first.second = i;
    alle.push_back(c);
  }
  sort(alle.begin(), alle.end());
  split();
  for (int i = 0; i < m; ++i) {
    l[i] = 0;
    r[i] = 1000000001;
    ans[i] = -1;
  }
  int fnd = 0;
  while (fnd < f.size()) {
    vector<pair<pair<int, int>, pair<int, int>>> q;
    for (pair<pair<int, int>, pair<int, int>> ed : f) {
      int i = ed.first.second;
      if (ans[i] != -1) continue;
      mid[i] = (1LL * l[i] + r[i]) / 2;
      ed.first.first = mid[i];
      q.push_back(ed);
    }
    sort(q.begin(), q.end());
    reverse(q.begin(), q.end());
    clr();
    for (auto c : e) {
      while (q.size() && q.back().first.first <= c.first.first) {
        int a = q.back().second.first, b = q.back().second.second,
            i = q.back().first.second;
        q.pop_back();
        if (get_set(a) == get_set(b)) {
          res[i] = 0;
        } else {
          res[i] = 1;
        }
      }
      int a = c.second.first, b = c.second.second;
      if (get_set(a) != get_set(b)) {
        unite(a, b);
      }
    }
    while (q.size()) {
      int i = q.back().first.second;
      q.pop_back();
      res[i] = 0;
    }
    for (pair<pair<int, int>, pair<int, int>> ed : f) {
      int i = ed.first.second;
      if (ans[i] != -1) continue;
      if (res[i] == 1) {
        l[i] = mid[i];
      } else {
        r[i] = mid[i];
      }
      if (l[i] + 1 == r[i]) {
        ans[i] = l[i];
        ++fnd;
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    if (ans[i] != -1) {
      printf("%d\n", ans[i]);
    }
  }
  return 0;
}