#include <bits/stdc++.h>
using namespace std;
function<void(void)> ____ = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
const int MAXN = 1e6 + 7;
vector<pair<pair<int, int>, pair<int, int>>> e;
int n, m, root[MAXN], used[MAXN];
pair<pair<int, int>, pair<int, int>> firste;
vector<pair<int, int>> G[MAXN];
int par[MAXN][20], depth[MAXN], cost[MAXN][20];
int findroot(int x) {
  if (x != root[x]) root[x] = findroot(root[x]);
  return root[x];
}
void dfs(int u, int f) {
  depth[u] = depth[f] + 1;
  par[u][0] = f;
  for (int i = 1; par[u][i - 1]; i++) {
    par[u][i] = par[par[u][i - 1]][i - 1];
    cost[u][i] = max(cost[u][i - 1], cost[par[u][i - 1]][i - 1]);
  }
  for (auto E : G[u]) {
    int v = E.first;
    int c = E.second;
    if (v == f) continue;
    cost[v][0] = c;
    dfs(v, u);
  }
}
int ikun(int u, int v) {
  int maxx = 0;
  if (depth[u] < depth[v]) swap(u, v);
  for (int i = 0; depth[u] - depth[v]; i++)
    if ((depth[u] - depth[v]) & (1 << i)) {
      maxx = max(maxx, cost[u][i]);
      u = par[u][i];
    }
  if (u == v) return maxx;
  for (int i = 19; i >= 0; i--)
    if (par[u][i] != par[v][i]) {
      maxx = max(maxx, max(cost[u][i], cost[v][i]));
      u = par[u][i];
      v = par[v][i];
    }
  return max(maxx, max(cost[u][0], cost[v][0]));
}
int main() {
  scanf("%d %d", &n, &m);
  e.resize(m);
  for (int i = 0; i < m; i++)
    scanf("%d %d %d", &e[i].first.first, &e[i].first.second,
          &e[i].second.first);
  for (int i = 0; i < m; i++) e[i].second.second = i;
  sort(e.begin(), e.end(),
       [](const pair<pair<int, int>, pair<int, int>> &A,
          const pair<pair<int, int>, pair<int, int>> &B) {
         return A.second.first < B.second.first;
       });
  for (int i = 1; i <= n; i++) root[i] = i;
  for (int i = 0; i < m; i++) {
    int u = e[i].first.first;
    int v = e[i].first.second;
    if (findroot(u) == findroot(v)) continue;
    root[findroot(u)] = findroot(v);
    used[e[i].second.second] = 1;
  }
  for (int i = 0; i < m; i++) {
    if (!used[e[i].second.second]) continue;
    auto p = e[i];
    G[p.first.first].emplace_back(make_pair(p.first.second, p.second.first));
    G[p.first.second].emplace_back(make_pair(p.first.first, p.second.first));
  }
  dfs(1, 0);
  sort(e.begin(), e.end(),
       [](const pair<pair<int, int>, pair<int, int>> &A,
          const pair<pair<int, int>, pair<int, int>> &B) {
         return A.second.second < B.second.second;
       });
  for (int i = 0; i < m; i++)
    if (!used[i]) printf("%d\n", ikun(e[i].first.first, e[i].first.second));
  return 0;
}
