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;
struct Node {
  int u, v, w, id;
  Node() {}
  Node(int _u, int _v, int _w, int _id) {
    u = _u;
    v = _v;
    w = _w;
    id = _id;
  }
  bool operator<(const Node &a) const { return w > a.w; }
};
int ar[5];
char buff[100];
void readLine() {
  gets(buff);
  int i = 0, len = strlen(buff), m = 0;
  while (i < len)
    if (buff[i] != ' ') {
      ar[m] = 0;
      while (i < len && buff[i] != ' ') ar[m] = ar[m] * 10 + buff[i++] - 48;
      m++;
    } else
      i++;
}
void printLine(int n) {
  int m = 0;
  do {
    buff[m++] = n % 10 + 48;
    n /= 10;
  } while (n);
  while (m--) putchar(buff[m]);
  putchar('\n');
}
int n, lab[1000100], depth[1000100];
pair<int, pair<int, int> > e[1000100 << 1];
vector<pair<int, int> > adj[1000100];
int P[1000100][21], L[1000100][21], k;
int getRoot(int u) {
  if (lab[u] < 0) return u;
  return lab[u] = getRoot(lab[u]);
}
void unionSet(int r1, int r2) {
  int x = lab[r1] + lab[r2];
  if (lab[r1] > lab[r2]) {
    lab[r1] = r2;
    lab[r2] = x;
  } else {
    lab[r1] = x;
    lab[r2] = r1;
  }
}
void dfs(int u, int p, int cost, int lvl) {
  P[u][0] = p;
  L[u][0] = cost;
  depth[u] = lvl;
  for (int i = 0, _n = (adj[u].size()); i < _n; i++) {
    int v = adj[u][i].first;
    if (v != p) dfs(v, u, adj[u][i].second, lvl + 1);
  }
}
void buildLCA() {
  dfs(1, -1, 0, 0);
  for (k = 0; (1 << (k + 1)) <= n; k++)
    ;
  for (int j = (1), _b = (k); j <= _b; j++) {
    for (int i = (1), _b = (n); i <= _b; i++)
      if (P[i][j - 1] == -1) {
        P[i][j] = P[i][j - 1];
        L[i][j] = L[i][j - 1];
      } else {
        P[i][j] = P[P[i][j - 1]][j - 1];
        L[i][j] = max(L[i][j - 1], L[P[i][j - 1]][j - 1]);
      }
  }
}
int solve(int u, int v) {
  int res = 0;
  if (depth[v] > depth[u]) swap(u, v);
  for (int j = (k), _b = (0); j >= _b; j--)
    if (P[u][j] != -1 && depth[u] - (1 << (j)) >= depth[v]) {
      res = max(res, L[u][j]);
      u = P[u][j];
    }
  if (u == v) return res;
  for (int j = (k), _b = (0); j >= _b; j--)
    if (P[u][j] != -1 && P[u][j] != P[v][j]) {
      res = max(res, max(L[u][j], L[v][j]));
      u = P[u][j];
      v = P[v][j];
    }
  res = max(res, L[u][0]);
  res = max(res, L[v][0]);
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int cases, caseNo = 1, m, u, v;
  while (caseNo--) {
    cin >> n >> m;
    for (int i = (1), _b = (n); i <= _b; i++) {
      lab[i] = -1;
      adj[i].clear();
    }
    priority_queue<Node> pq;
    for (int i = 0, _n = (m); i < _n; i++) {
      cin >> ar[0] >> ar[1] >> ar[2];
      pq.push(Node(ar[0], ar[1], ar[2], i));
    }
    vector<pair<int, pair<int, int> > > stor;
    while (!pq.empty()) {
      Node temp = pq.top();
      u = getRoot(temp.u);
      v = getRoot(temp.v);
      pq.pop();
      if (u != v) {
        unionSet(u, v);
        adj[temp.u].push_back(pair<int, int>(temp.v, temp.w));
        adj[temp.v].push_back(pair<int, int>(temp.u, temp.w));
      } else {
        stor.push_back({temp.id, {temp.u, temp.v}});
      }
    }
    int ans[m + 1];
    memset(ans, -1, sizeof ans);
    buildLCA();
    int d = stor.size();
    for (int i = 0; i < d; i++) {
      ans[stor[i].first] = (solve(stor[i].second.first, stor[i].second.second));
    }
    for (int i = 0; i < m; i++) {
      if (ans[i] != -1) cout << ans[i] << endl;
    }
  }
  return 0;
}